-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
85 lines (73 loc) · 2.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
// Copyright 2015, Daniel Garcia <daniel@danielgarcia.info>
// yuml2 is distributed under the MIT license.
//
// Based on the python yuml client https://github.com/wandernauta/yuml
// by Wander Nauta
import (
"flag"
"fmt"
"io"
"os"
"github.com/daniel-garcia/yuml2/go-yuml"
)
const version = "0.2.0"
var (
options = yuml.Options{}
)
func init() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s v%s\n", os.Args[0], version)
fmt.Fprintf(os.Stderr, "Usage: %s [options] INPUT_FILE OUTPUT_FILE\n", os.Args[0])
fmt.Fprintf(os.Stderr, "'-' can be used for stdin or stdout\n")
flag.PrintDefaults()
}
if endpoint := os.Getenv("YUML_ENDPOINT"); len(endpoint) > 0 {
yuml.BaseURL = endpoint
}
flag.IntVar(&options.Scale, "scale", 0, "percentage to scale output")
flag.StringVar(&options.Direction, "direction", "LR", "text direction (LR, RL, TD)")
flag.StringVar(&options.Style, "style", "scruffy", "style of image (scruffy, nofunky, plain)")
flag.StringVar(&options.Format, "format", "", "format of output (png, pdf, jpg, svg)")
flag.StringVar(&options.Use, "t", "class", "type of diagram (class, activity, usecase)")
flag.StringVar(ÿ.BaseURL, "u", yuml.BaseURL, "base url for service (YUML_ENDPOINT) ")
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) != 2 {
flag.Usage()
os.Exit(1)
}
var input io.Reader
var output io.Writer
if args[0] == "-" {
input = os.Stdin
} else {
f, err := os.Open(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "could not open %s: %s\n", args[0], err)
os.Exit(1)
}
defer f.Close()
input = f
}
if args[1] == "-" {
output = os.Stdout
} else {
var err error
options.Format, err = getExtensionType(options.Format, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "could not determine output type: %s\n", err)
}
f, err := os.Create(args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "could not open %s: %s\n", args[1], err)
}
defer f.Close()
output = f
}
if err := yuml.Generate(options, input, output); err != nil {
fmt.Fprintf(os.Stderr, "could not generate diagram: %s\n", err)
}
}