1package main
2
3import (
4 "fmt"
5 "os"
6
7 "cddx2yaml/internal"
8
9 "gopkg.in/yaml.v3"
10)
11
12func main() {
13 if len(os.Args) > 1 && (os.Args[1] == "-v" || os.Args[1] == "--version") {
14 fmt.Println(internal.Version)
15 return
16 }
17
18 path, outputPath := "circuit.cddx", "circuit.yaml"
19
20 if len(os.Args) > 1 {
21 path = os.Args[1]
22 }
23 if len(os.Args) > 2 {
24 outputPath = os.Args[2]
25 }
26 circuit, err := internal.LoadFile(path)
27 if err != nil {
28 fmt.Fprintf(os.Stderr, "Error loading file: %v\n", err)
29 os.Exit(1)
30 }
31
32 outputFile, err := os.Create(outputPath)
33 if err != nil {
34 fmt.Fprintf(os.Stderr, "Error creating output file: %v\n", err)
35 os.Exit(1)
36 }
37 defer outputFile.Close()
38
39 encFile := yaml.NewEncoder(outputFile)
40 encFile.SetIndent(2)
41 if err := encFile.Encode(circuit); err != nil {
42 fmt.Fprintf(os.Stderr, "Error encoding YAML to file: %v\n", err)
43 os.Exit(1)
44 }
45
46}