yuzutech / kroki-cli

A Kroki CLI
MIT License
65 stars 6 forks source link

First release of the kroki CLI #1

Closed ggrossetie closed 5 years ago

ggrossetie commented 5 years ago

Usage

kroki convert hello.dot

By default the output format is svg and the diagram type is inferred from the file name. The above command is equivalent to:

kroki convert hello.dot --type dot --format svg

Read from stdin, output to stdout and use svg as the default output format.

cat hello.dot | kroki convert --type dot -

Read from stdin, output to out.png and use png as output format.

cat hello.dot | kroki convert --type dot -o out.png -

Read the file hello.dot and output to out.png.

kroki convert hello.dot -o out.png

Read the file hello.dot and output to stdout.

kroki convert hello.dot -o -

TODO

mcorbin commented 5 years ago

You could avoid global variables by defining the flags in the command:

var convertCmd = &cobra.Command{
    Use:           "convert file",
    Short:         "Convert text diagram to image",
        Flags: []cli.Flag{ 
        cli.StringFlag{
            Name:  "config",
            Usage: "description",
                         // use Value: "foo" for default values
         }
},

And then:

config := (cmd.String("config"))
ggrossetie commented 5 years ago

you committed a main binary.

Oops :sweat_smile:

ggrossetie commented 5 years ago

@mcorbin I think we should use io.Reader and io.Writer abstraction to read the diagram source and write the result. It's also easier to test as you can replace the Reader and/or the Writer with a Buffer.

I think kroki-go should provide the following functions:

func (c *Client) FromReader(reader io.Reader, diagramType DiagramType, imageFormat ImageFormat) (string, error) {}

func (c *Client) Write(writer io.Writer, result string) error {}
ggrossetie commented 5 years ago

@mcorbin Should be ready to go.

After this pull request is merged, I will make a few changes to kroki-go then release a new version and adjust the CLI code.