FAQ
Frankly, I'm almost satisfied by the standard `flag` parser.
That's why I don't like it:

     v := flag.Bool("v", false, "print version to stdout and exit")
     flag.Parse()
     a := flag.Args()
     if ! *v {
         fmt.Println(a)
     }

And then I run `my_program some args here -v`. Flag doesn't notice the -v
switch, because it's at the end. I doubt, this is nice CLI behaviour.

Please recommend a command-line parser, that will parse this example
correctly (that is: interpreting `-v` even at the end of command-line,
after un-prefixed args).
Thanks.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • C Banning at Jan 12, 2015 at 10:04 pm
    Try:

         v := flag.Bool("v", false, "print version to stdout and exit")
         *sort.Strings(os.Args[1:])*
         flag.Parse()
         a := flag.Args()
         if ! *v {
             fmt.Println(a)
         }
    On Monday, January 12, 2015 at 2:45:43 PM UTC-6, Chai Tadada wrote:

    Frankly, I'm almost satisfied by the standard `flag` parser.
    That's why I don't like it:

    v := flag.Bool("v", false, "print version to stdout and exit")
    flag.Parse()
    a := flag.Args()
    if ! *v {
    fmt.Println(a)
    }

    And then I run `my_program some args here -v`. Flag doesn't notice the -v
    switch, because it's at the end. I doubt, this is nice CLI behaviour.

    Please recommend a command-line parser, that will parse this example
    correctly (that is: interpreting `-v` even at the end of command-line,
    after un-prefixed args).
    Thanks.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Sebastien Binet at Jan 12, 2015 at 10:16 pm

    On Mon, Jan 12, 2015 at 11:04 PM, C Banning wrote:
    Try:

    v := flag.Bool("v", false, "print version to stdout and exit")
    sort.Strings(os.Args[1:])
    flag.Parse()
    a := flag.Args()
    if ! *v {
    fmt.Println(a)
    }
    hum... wouldn't this break:
    $ my-cmd -opt value
    $ my-cmd -opt=value

    ?
    (which should be equivalent)

    -s
    On Monday, January 12, 2015 at 2:45:43 PM UTC-6, Chai Tadada wrote:

    Frankly, I'm almost satisfied by the standard `flag` parser.
    That's why I don't like it:

    v := flag.Bool("v", false, "print version to stdout and exit")
    flag.Parse()
    a := flag.Args()
    if ! *v {
    fmt.Println(a)
    }

    And then I run `my_program some args here -v`. Flag doesn't notice the -v
    switch, because it's at the end. I doubt, this is nice CLI behaviour.

    Please recommend a command-line parser, that will parse this example
    correctly (that is: interpreting `-v` even at the end of command-line, after
    un-prefixed args).
    Thanks.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • C Banning at Jan 12, 2015 at 10:20 pm
    Yup it does. Never use that myself; so forgot that use case.
    On Monday, January 12, 2015 at 4:16:59 PM UTC-6, Sebastien Binet wrote:

    On Mon, Jan 12, 2015 at 11:04 PM, C Banning <clba...@gmail.com
    <javascript:>> wrote:
    Try:

    v := flag.Bool("v", false, "print version to stdout and exit")
    sort.Strings(os.Args[1:])
    flag.Parse()
    a := flag.Args()
    if ! *v {
    fmt.Println(a)
    }
    hum... wouldn't this break:
    $ my-cmd -opt value
    $ my-cmd -opt=value

    ?
    (which should be equivalent)

    -s
    On Monday, January 12, 2015 at 2:45:43 PM UTC-6, Chai Tadada wrote:

    Frankly, I'm almost satisfied by the standard `flag` parser.
    That's why I don't like it:

    v := flag.Bool("v", false, "print version to stdout and exit")
    flag.Parse()
    a := flag.Args()
    if ! *v {
    fmt.Println(a)
    }

    And then I run `my_program some args here -v`. Flag doesn't notice the
    -v
    switch, because it's at the end. I doubt, this is nice CLI behaviour.

    Please recommend a command-line parser, that will parse this example
    correctly (that is: interpreting `-v` even at the end of command-line,
    after
    un-prefixed args).
    Thanks.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Nigel Tao at Jan 13, 2015 at 12:33 am

    On Tue, Jan 13, 2015 at 9:04 AM, C Banning wrote:
    sort.Strings(os.Args[1:])
    That would change
    cp foo bar
    to
    cp bar foo

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Chai Tadada at Jan 13, 2015 at 3:52 pm
    вторник, 13 января 2015 г., 0:04:54 UTC+2 пользователь C Banning написал:
    Try:

    v := flag.Bool("v", false, "print version to stdout and exit")
    *sort.Strings(os.Args[1:])*
    flag.Parse()
    a := flag.Args()
    if ! *v {
    fmt.Println(a)
    }
    A nice suggestion, but, as already mentioned, this produces broken results.

    Meanwhile found the kingpin library, cheked it out. It seems broken in the
    same way as flag is.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Nick Craig-Wood at Jan 13, 2015 at 4:49 pm

    On 12/01/15 20:45, Chai Tadada wrote:
    Frankly, I'm almost satisfied by the standard `flag` parser.
    That's why I don't like it:

    v := flag.Bool("v", false, "print version to stdout and exit")
    flag.Parse()
    a := flag.Args()
    if ! *v {
    fmt.Println(a)
    }

    And then I run `my_program some args here -v`. Flag doesn't notice the
    -v switch, because it's at the end. I doubt, this is nice CLI behaviour.

    Please recommend a command-line parser, that will parse this example
    correctly (that is: interpreting `-v` even at the end of command-line,
    after un-prefixed args).
    I've used this in one of my projects. I like it because the interface
    and philosophy is identical to the flag package, but it allows all the
    things people expect from GNU style flags, like putting them after the
    arguments, or combining single letter flags, or --flags.

    https://github.com/ogier/pflag

    --
    Nick Craig-Wood <nick@craig-wood.com> -- http://www.craig-wood.com/nick

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ktyaktya Tm at Jan 14, 2015 at 3:54 pm
    вторник, 13 января 2015 г., 18:49:20 UTC+2 пользователь Nick Craig-Wood
    написал:
    I've used this in one of my projects. I like it because the interface
    and philosophy is identical to the flag package, but it allows all the
    things people expect from GNU style flags, like putting them after the
    arguments, or combining single letter flags, or --flags.

    https://github.com/ogier/pflag
    Yay! Nick, thanks a lot for this link (somehow didn't find it in Google).

    This is really a nice library, it suits my case and I like it too.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Larry Clapp at Jan 14, 2015 at 6:03 pm

    On Monday, January 12, 2015 at 3:45:43 PM UTC-5, Chai Tadada wrote:
    And then I run `my_program some args here -v`. Flag doesn't notice the -v
    switch, because it's at the end. I doubt, this is nice CLI behaviour.
    I don't know about "nice", but it is pretty *standard* for Unix programs to
    stop parsing flags at the first option that doesn't start with a dash.

    -- Larry

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Chai Tadada at Jan 14, 2015 at 6:19 pm
    среда, 14 января 2015 г., 20:03:29 UTC+2 пользователь Larry Clapp написал:
    On Monday, January 12, 2015 at 3:45:43 PM UTC-5, Chai Tadada wrote:

    And then I run `my_program some args here -v`. Flag doesn't notice the -v
    switch, because it's at the end. I doubt, this is nice CLI behaviour.
    I don't know about "nice", but it is pretty *standard* for Unix programs
    to stop parsing flags at the first option that doesn't start with a dash.
    That actually depends what exactly do you mean by 'Unix programs'. SVR4?
    4.3BSD? SunOS? Unixware? Frankly, I used some of the listed stuff and don't
    want to go back, nor to their supplied software,

    GNU utilities (yes, I'm aware that's GNU's Not Unix) do the behaviour, I
    like. BSD (at least the ones in OS X 10.8) do the behaviour, you like.

    Have you ever interactively edited a command from your shell history? If
    so, undoubtely you will agree, this style of argument parsing can be more
    convenient to user (no need to jump at the beginning of the line and to the
    second word, that saves time).

    In fact, personally I'm using GNU coreutils on OS X just because of this
    inconvenient way of editing the command line in system-supplied utilities.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Larry Clapp at Jan 14, 2015 at 6:48 pm

    On Wednesday, January 14, 2015 at 1:19:10 PM UTC-5, Chai Tadada wrote:
    среда, 14 января 2015 г., 20:03:29 UTC+2 пользователь Larry Clapp написал:
    On Monday, January 12, 2015 at 3:45:43 PM UTC-5, Chai Tadada wrote:

    And then I run `my_program some args here -v`. Flag doesn't notice the
    -v switch, because it's at the end. I doubt, this is nice CLI behaviour.
    I don't know about "nice", but it is pretty *standard* for Unix programs
    to stop parsing flags at the first option that doesn't start with a dash.
    That actually depends what exactly do you mean by 'Unix programs'. SVR4?
    4.3BSD? SunOS? Unixware? Frankly, I used some of the listed stuff and don't
    want to go back, nor to their supplied software,
    Fair enough. It's been a long time since I used anything but some flavor
    of Linux[1]. Good point..

    GNU utilities (yes, I'm aware that's GNU's Not Unix) do the behaviour, I
    like. BSD (at least the ones in OS X 10.8) do the behaviour, you like.
    I actually didn't know that. "ls dirname -l" works the same as "ls -l
    dirname". I am quite surprised. Thanks!

    -- Larry


    [1] That is, the only Unix-y environment has been Linux. I use Windows &
    Mac OS too. Hmm, Macs are Unix-y too; I never noticed the behavior you
    described there, either, but perhaps only because I never tried it.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 12, '15 at 8:45p
activeJan 14, '15 at 6:48p
posts11
users7
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase