pki-io / admin

Other
15 stars 7 forks source link

Problems with subcommand args #1

Closed zeroXten closed 9 years ago

zeroXten commented 9 years ago

I added the following line to the usage under "Examples":

pki.io init --org=<org> --admin=<admin>

Then, when running I just got the generic usage:

$ go run *.go init --org hello --admin fscott
Usage:
    pki.io [--version] <command> [<args>...]
exit status 1

Running this worked:

$ go run *.go init 
map[<command>:init <args>:[] --version:false]
command arguments:
[]
init
Hi
Not Implemented ...yet
exit status 1

In order to get this working I had to reformat the usage a bit:

usage := `pki.io
Usage:
  pki.io init --org=<org> --admin=<admin>
  pki.io --version

Options:
  -h --help   Show this screen
  --version   Show version
  --org=<name> Organisation name
  --admin=<name> Administrator name
`

But that meant not using a subcommand function:

    arguments, _ := docopt.Parse(usage, nil, true, "pki.io", false)
    fmt.Println(arguments)

    if arguments["init"].(bool) {
        runInit(arguments)
    }

Here is the output...

$ go run *.go init --org test --admin babc
map[init:true --org:test --admin:babc --version:false]
&{.}
Creating Org entity
Creating Admin entity
Generating Org keys
zeroXten commented 9 years ago

Had to update the example failure. What I provided originally was broken for other reasons but wasn't the only test I had run.

thanasisk commented 9 years ago

Is this still a failure under fraser-scott branch? If yes, we can merge to master

zeroXten commented 9 years ago

fscott-cli branch is working, but I had to change the way I structured the opts. One thing that might make sense, if it is possible, is to have the opts parsing split across the levels. So top level commands like

pki.io ca
pki.io admin
pki.io org

etc. are handled in the main file, then opts specific to those commands are parsed in the relevant functions. E.g. runCA(...) would parse

pki.io ca new
pki.io ca update

etc.

zeroXten commented 9 years ago

Implementation should be modelled on this https://github.com/docopt/docopt.go/blob/master/examples/git/git.go

So, top level usage and parsing, and per-command usage and parsing.

zeroXten commented 9 years ago

Stealing this as I'm trying to work out the CLI UX anyway.

jonbonazza commented 9 years ago

Havent looked at the existing code, but the flags package might be useful here.

On Fri, Jan 23, 2015, 12:18 PM Fraser Scott notifications@github.com wrote:

Stealing this as I'm trying to work out the CLI UX anyway.

— Reply to this email directly or view it on GitHub https://github.com/pki-io/admin/issues/1#issuecomment-71258486.

thanasisk commented 9 years ago

Hi Jon, early in the project we decided to use a 3rd party library for command line parsing - you can see details in the gomfile

jonbonazza commented 9 years ago

Ah okay, that makes sense. I actually haven't looked at clarg parsing libs yet for golang. I'll have to check them out.

On Fri Jan 23 2015 at 12:26:17 PM Athanasios Kostopoulos < notifications@github.com> wrote:

Hi Jon, early in the project we decided to use a 3rd party library for command line parsing

— Reply to this email directly or view it on GitHub https://github.com/pki-io/admin/issues/1#issuecomment-71259696.

zeroXten commented 9 years ago

I think this is done now. Multi level docopt seems to work nicely.