16 comments

  • sametmax 1863 days ago
    I used to love doctopt, but with usage your realise:

    - i18n is made hard

    - syntax errors are not caught by tooling

    - you don't get automatic args checking or env var override

    Eventually, a well made programmative API is better.

    • thechao 1863 days ago
      I used docopt in production for years, before switching off of it.

      My main issues were that the author of docopt doesn't know anything about language grammars & parsing. That's fine — we all start somewhere. But he insists that defining a grammar (and having a rational parser) aren't useful or even possible! If, instead, there were a normative spec (and this requires only the slightest change to edge-cases that aren't tested by his test-suite, anyways), then it'd be possible to really roll out a much more robust docopt than what currently occurs.

      With a grammar you'd be able to roll out AST=>AST transforms, and update the parsing strategy of the command lines, i.e., portability between CLI flavors between new/old style POSIX, Windows, etc. You'd have the ability to do i18n, you could catch errors both in the docopt spec of your parser, and in the parsing of the command line options, etc.

      • celicoo 1863 days ago
        I've started with a fork of Docopt, but then I realized the exact same thing - the maintainers didn't use the best parsing practices, so I've just deleted the fork and started Docli. If you follow the tutorial you will see that you can print the AST produced by Docli's parser :D.
      • cstejerean 1863 days ago
        So did you end up making something better? I’ve been using docopt for years but I’ll gladly consider switching to a better alternative.
    • celicoo 1863 days ago
      Totally! I love the idea of Docopt, but I don't like the implementation - that was the perfect excuse to start Docli (Although some of these points were not YET addressed).
    • coldtea 1863 days ago
      >- i18n is made hard

      It's also mostly redundant. I'd expect CLI users to be able to parse flags and --help messages in english.

      And I'm not saying it as a native english speaker -- which I'm not. Without english knowledge you can't parse 99% of existing, never to be i18n standard UNIX commands, flags, and manpages.

      • thayne 1863 days ago
        > Without english knowledge you can't parse 99% of existing, never to be i18n standard UNIX commands, flags, and manpages.

        That makes me sad.

        • coldtea 1863 days ago
          That makes me happy. I'm all for national languages, ethnic nuances etc (I'm not English-native-speaker myself), great spell checkers, voice recognition, fonts, etc for all languages.

          But for text work (writing, reading, etc).

          Not on my fucking programming languages (like bizarro foreign variable names in source code), and ideally, not on my CLI either.

          Let's have a common universal language in our domain.

          Doctors get to use latin names and common terms for tons of medical staff whatever their country. Pilots get to speak english with every control tower all around the world.

          Computer work should have some of that too.

          • thayne 1855 days ago
            There's a difference between having source code and CLI commands in a hodge-podge of languages and not having translations of man pages.
      • e12e 1863 days ago
        I'm not sure if 99% is accurate - unless you intentionally include internal tooling ("standard UNIX commands" implies not).

        Now, if you mean "actual UNIX", I'm not sure - but at least gnu is pretty widely translated. Not sure where the bsds stand on this.

      • realusername 1862 days ago
        > which I'm not. Without english knowledge you can't parse 99% of existing, never to be i18n standard UNIX commands, flags, and manpages.

        Most of the standard GNU commands are translated, at least I can't think of any which is not.

  • hwj 1863 days ago
    This is a Go library that parses a usage string into an AST.
    • umvi 1863 days ago
      "Docli" makes it sound like a generic documentation generator for CLIs.

      IMO name should make it clear it is Go-only. Something like "GoastArgs: a Go library that parses a usage string/CLI args into an AST"

      • FreeFull 1863 days ago
        I am not a Go user so I can't speak about Go specifically, but I feel like including the name of the language in the library name is in general an anti-pattern, since generally when you look for a library to do something in language A, you aren't going to get results using language B anyway.
      • celicoo 1863 days ago
        Thanks for the feedback umvi. I will be working on making it clear that Docli is a Go library.
        • dromedary512 1863 days ago
          But, for the love of God, please don't put the word "Go" in the name :D
    • celicoo 1863 days ago
      Exactly! Thank you for clarifying that. The documentation still needs some improvements, and this is one of them.
    • AbraKdabra 1863 days ago
      Thanks, it's very disappointing when a comment describes the product better than the official webpage.
      • AnanasAttack 1863 days ago
        Not that unusual really. Whenever you hear about new stuff, chances are it's better to look it up on Wikipedia first.
        • rabidrat 1863 days ago
          Docli doesn't seem to have a Wikipedia article yet.
        • thayne 1863 days ago
          Not unusual. But still disappointing.
  • ilovecaching 1863 days ago
    I still feel that cobra and docopt are ungoish despite the author of cobra getting hired on. There's simply too much magic to both of them. I would much rather they improve flags, which is what I use. It really doesn't take that much with flags to add subcommands, etc, but it could be made better.
    • rajangdavis 1863 days ago
      Can you elaborate on what makes cobra ungoish? I had built a CLI using it without prior knowledge of Go (but with a background in scripting languages and a some C#) and it seemed pretty straightforward.

      The only issue that I can tell was that you can possibly create errors that the compiler can miss, but it's been pretty solid otherwise.

      • ilovecaching 1863 days ago
        Cobra is very much a kitchen sink approach with a lot of gen. I'd rather have less dependency and write just using the stdlib without the kitchen sink, which is more goish.
        • rajangdavis 1863 days ago
          That makes a lot of sense.

          I guess the parallel for me would be using Rack as opposed to Rails for Ruby.

          Thanks for responding!

    • weberc2 1863 days ago
      I use github.com/urfave/cli, but I almost always end up wrapping it with my own declarative framework. Gradually said framework is becoming more general purpose and suitable for general use, at which point I'll probably open source it and hopefully it will make someone's life better.
  • deforciant 1863 days ago
    For servers I prefer using: https://github.com/alecthomas/kingpin, allows you to really nicely expand based on main arguments with flags. Also, setting defaults is a joy.

    For CLIs - https://github.com/spf13/cobra.

    However, will definitely try out Docli whenever I start building something new :)

  • thanatos_dem 1863 days ago
    Seems like Cobra is pretty well established in this space - https://github.com/spf13/cobra

    Tho admittedly it works in reverse; it generates the doc/help info rather than parsing it into an AST. It addresses the “boilerplate” issue with code gen as well, but it has a CLI to generate code that’s pretty powerful.

    For instance, how does docli handle subcommands? How about global vs command specific flags? For any case beyond the basic single command CLI, it seems like there would need to be all sorts of magic and non-obvious formatting requirements on the doc string.

    • celicoo 1855 days ago
      Hey! I've opened an issue to discuss about the subcommands feature: https://github.com/celicoo/docli/issues/10

      I would love to know your opinion about it.

    • celicoo 1863 days ago
      Hey thanatos_dem

      Right now Docli can't handle those scenarios, but it will on the next big release - which it might take a while because it's not trivial to add those features and keep the API simple.

  • matt-attack 1863 days ago
    Anyone have a recommendation for Node.js? I've been extremely frustrated with commander [1].

    [1] https://www.npmjs.com/package/commander

    • Kamshak 1863 days ago
      • curry-castaway 1863 days ago
        I can second this recommendation – Oclif[0] is an absolute pleasure to use. I'd even encourage developers who aren't at a "full-stack Node.js shop" to give it a shot.

        I'm particularly impressed with the bash and zsh autocomplete support. I was delighted when I finished setting it up and everything worked perfectly on the first try.

        [0]: https://oclif.io/

      • jessaustin 1863 days ago
        HN had something on this a few months back, "12 Factor CLI Apps":

        https://news.ycombinator.com/item?id=18172689

    • tln 1863 days ago
      There are lots of different approaches to defining the arguments and options.

      * You can build up a structure programmatically to define the arguments, as in commander, and then the usage and shape of the parsed result are implied.

      * You can provide the usage, as in docopt, and then the structure to define the args and shape of the parsed result are implied.

      * Or you can take the approach I did in fncli, which is to provide the shape of parsed result, as a function signature, and let the structure to define the args and usage be implied.

      https://www.npmjs.com/package/fncli

      This is possible because Javascript spec includes the function arguments as a string that can be parsed at run time.

      Because you're using ES6 syntax, you don't have to learn a new syntax (unlike docli or docopt). And although there are limitations, I've found this approach to handle modest CLI needs with an absolute minimum of fuss.

    • tmpfs 1863 days ago
      You may want to try my markdown based CLI definition tool:

      https://github.com/mkdoc/mkcli

      Generates help files, man pages, shell autocomplete for bash etc

    • timdorr 1863 days ago
      Lots of folks seem to like Yargs: https://github.com/yargs/yargs
  • calebwin 1863 days ago
    I really like that graphic for the website and README! Did you make it?
  • maxaf 1863 days ago
  • CamouflagedKiwi 1863 days ago
    Not really a fan of this approach. I don't like the duality between the help text and the struct it gets bound to - much prefer the approach of generating the help text from a struct.

    https://github.com/jessevdk/go-flags is my favourite option; it's lightweight but amazingly featureful, and I much prefer the declarative approach to a programmatic one like the standard library flags package

  • pushpop 1863 days ago
    Their example here confuse me:

    https://github.com/celicoo/docli/blob/master/examples/terraf...

    `workspace` isn't a boolean flag. So it isn't clear from that example how - or even if - docli can work with more complex conditional arguments.

    Is someone with any familiarity with this project able to advise how you'd handle that in docli?

    • granra 1863 days ago
      All the variables in in the `Commands` and `AllOtherCommands` are bools.

      In Go you can do `a, b, c bool` and they'll all be of type bool.

      • pushpop 1863 days ago
        Yeah I got that. My point is that ‘workspace’ isn’t a Boolean flag in terraform. It requires additional flags to function, eg

          terraform workspace new granra
        
        ‘workspace’ is effectively the CLI flags equivalent of a submenu.
        • granra 1862 days ago
          Oh I see. It looks like docli sets the flag as true if it was passed as a parameter to the program.

          So you do:

          var terraform Terraform

          args.Bind(&terraform)

          if terraform.Workspace {

            // do workspace stuff
          
          }

          I think.

          EDIT: I don't know how hackernews formatting works :/

          • pushpop 1862 days ago
            That seems really messy to be honest because you can’t then ensure flags are nested correctly.

            I guess for simple purposes this is fine though.

  • mongol 1863 days ago
    For my purpose, go-flags was a great fit.

    https://github.com/jessevdk/go-flags

  • henvic 1863 days ago
    cobra is working pretty well for my needs: https://asciinema.org/a/192043

    Nice to see a declarative approach, though. It certainly looks more natural. I'm certainly going to give it a try.

  • jlesk 1863 days ago
    I really like the line art logo on the site, but it's 2.4 MB (avatar.png).

    Might want to size it down and run it through TinyPNG. :)

    • celicoo 1863 days ago
      Oh, I didn't notice how big it is! I will fix that as soon as possible. Thanks for the feedback.
  • bfrydl 1863 days ago
    It's a little strange that I had to open the tutorial to find out what language this is for.
    • skocznymroczny 1863 days ago
      I was going to guess Rust, but turns out it's Go.
      • leshow 1863 days ago
        Personally, I like Rust's a bit better:

        https://github.com/TeXitoi/structopt

        edit: because it's type safe!

      • 99052882514569 1863 days ago
        Wouldn't `gocli` be a better name then?
        • Gipetto 1863 days ago
          The solution here is clearly to write a new language named "do".
        • bitcoinofficial 1863 days ago
          Does having a programming language name in a program name make the program better? I don't get it, sorry.
          • lucideer 1863 days ago
            It certainly makes it a lot easier to understand what it's for...
        • fwip 1863 days ago
          I think it's a portmanteau of "doc" and "cli" - because it's a CLI options parser that is generated from documentation.
    • celicoo 1863 days ago
      Hey, I'm really sorry about that! I'm still working on the details, but thank you for the feedback.
  • kvakvs 1863 days ago
    Please put the language it is intended for somewhere as close to the page top as possible. The world isn't all Go.