Live data from Hacker News

Fang, the CLI Starter Kit

github.com

21–30 of 34 posts

Re: Fang, the CLI Starter Kit

#21
It would be really cool if Fang could generate a TUI form for your app with https://github.com/charmbracelet/huh (by the same org). Is something like that on the roadmap?

Similar work: https://github.com/chriskiehl/Gooey and https://github.com/Sorcerio/Argparse-Interface

I've wanted to do TUI form generation for my own CLI framework since 2023 ( https://github.com/bbkane/warg/issues/71 ), but I still haven't gotten around to it

Re: Fang, the CLI Starter Kit

#22
post #5

Just re-wrote an internal CLI to urfave from custom, but having issues with v3 autocomplete scripts. Might just take the time to switch over to cobra and use this.

I think kong[1] is better than both options although cobra is by far the most popular. Might be worth a look.

Definitely won't look as pretty as the parent project though but I prefer kong in terms of the actual code you need to write.

[1] https://github.com/alecthomas/kong

Re: Fang, the CLI Starter Kit

#23

Stubborn complaint (and maybe a hot take): I dislike CLIs that try to be overly pretty. I don't receive any tangible benefit as the user from the "fancy" (their words) help output. I'd much rather simple plain text output that looks like all the other tools I already use.

I like colour in a tool like 'bat' or 'jless' where it helps me visually scan, but other than that I'd agree with you

Re: Fang, the CLI Starter Kit

#24

Stubborn complaint (and maybe a hot take): I dislike CLIs that try to be overly pretty. I don't receive any tangible benefit as the user from the "fancy" (their words) help output. I'd much rather simple plain text output that looks like all the other tools I already use.

> overly pretty

"bling" is the word you're looking for. It's just a fashion. Fashion is famously cyclic, and we're just in a high-ornamentation part of the cycle. Eventually, restraint will become fashionable again.

Re: Fang, the CLI Starter Kit

#25
post #19

Stubborn complaint (and maybe a hot take): I dislike CLIs that try to be overly pretty. I don't receive any tangible benefit as the user from the "fancy" (their words) help output. I'd much rather simple plain text output that looks like all the other tools I already use.

Alignment (and maybe bold text for some things) is all you need in >95% of cases, IMHO. One of the downsides of a lot of these tools is that's exactly what they don't do well: many things don't align or wrap nicely. For example, here's a comparison of this fang library vs one where I just raw-dogged the usage text: https://imgur.com/a/QWh9TLD – the nice alignment does a lot more than colours. Especially for larger pr…

> One of the downsides of a lot of these tools is that's exactly what they don't do well: many things don't align or wrap nicely.

Bling is easy. Unsexy usability details are hard.

    Z$ time ./example/run
    You ran the root command. Now try --help.
    ./example/run  0.13s user 0.27s system 177% cpu 0.228 total
Why would an example program take 228ms?

    Z$ ./example/run --name='abc def'
    
      Unknown command "def" for "example".                                                            

      Try --help for usage.

Huh? 'abc def' is one shell word. --name=abc works fine.

     Z$ ./example/run --name ''
          
       ERROR  
         
       Flag needs an argument: --name.                                                                 

       Try --help for usage.
But I did give it an argument: the empty string.

And why is the output indented two columns from the left margin anyway?

    Z$ ./example/run ''
    You ran the root command. Now try --help.

    Z$ ./example/run 'x'
          
      ERROR  
          
      Unknown command "x" for "example".                                                              

      Try --help for usage.
Should have produced an error using '' for the subcommand name.

    Z$ ./example/run sub "multi-word quoted string" --flag "another quoted string"
    Ran the sub command!

    Z$ ./example/run --help

      A little example program!                                                                         
                                                                                                        
      It doesn’t really do anything, but that’s the point.™                                             

      USAGE  


        example [command] [args] [--flags]                                     


      EXAMPLES  


        # Run it:                                                              
        example                                                                
                                                                               
        # Run it with some arguments:                                          
        example --name=Carlos -a -s Becker -a                                  
                                                                               
        # Run a subcommand with an argument:                                   
        example sub --async --foo=xyz --async arguments                        
                                                                               
        # Run with a quoted string:                                            
        example sub "quoted string"                                            
                                                                               
        # Mix and match:                                                       
        example sub "multi-word quoted string" --flag "another quoted string"  


      COMMANDS  

        help [command]                  Help about any command
        sub [command] [args] [--flags]  An example subcommand
        throw                           Throws an error

      FLAGS  

         -a --async                     Run async
         -h --help                      Help for example
         --name                         Your name (jane)
         -s --surname                   Your surname (doe)
         -v --version                   Version for example


    Z$ ./example/run sub "multi-word quoted string" --flag "another quoted string"
    zsh: command not found: example sub multi-word quoted string --flag another quoted string
Huh? Why did the command work when I typed it myself but not when I pasted from the help output?

Oh. Because the help output is using nbsp, not regular spaces.

Anyway, command line interfaces have a surprising number of hairy corner cases. I'd rather have boring monochrome that gets them right than an all-colorful theme auto-shell-completion-generating system that doesn't.

Re: Fang, the CLI Starter Kit

#26
post #22
post #5

Just re-wrote an internal CLI to urfave from custom, but having issues with v3 autocomplete scripts. Might just take the time to switch over to cobra and use this.

I think kong[1] is better than both options although cobra is by far the most popular. Might be worth a look. Definitely won't look as pretty as the parent project though but I prefer kong in terms of the actual code you need to write. [1] https://github.com/alecthomas/kong

OP said they want completion support, which Kong doesn't include. https://github.com/jotaen/kong-completion exists, but the last commit was 2 years ago.

Re: Fang, the CLI Starter Kit

#27
post #3

I’ve been maintaining rust-starter[!] for quite sometime now. It is kind of the equivalent of fang but for Rust. It uses Clap which is the equivalent of Cobra; though I don’t think Clap has the same kind of fancy output? Throughout these years, I have found that cross-compiling is the most challenging part of creating a CLI. When you are building a web back-end, you control the execution environment (usually linux).…

I looked into how rust does does it for rustup, and they have a pretty amazing set of gh actions to build for their architectures, I can't find the GH link now tho

for speed you can look for vendors like https://depot.dev/

Re: Fang, the CLI Starter Kit

#28
post #19

Earlier quoted context omitted.

Alignment (and maybe bold text for some things) is all you need in >95% of cases, IMHO. One of the downsides of a lot of these tools is that's exactly what they don't do well: many things don't align or wrap nicely. For example, here's a comparison of this fang library vs one where I just raw-dogged the usage text: https://imgur.com/a/QWh9TLD – the nice alignment does a lot more than colours. Especially for larger pr…

> One of the downsides of a lot of these tools is that's exactly what they don't do well: many things don't align or wrap nicely. Bling is easy. Unsexy usability details are hard. Z$ time ./example/run You ran the root command. Now try --help. ./example/run 0.13s user 0.27s system 177% cpu 0.228 total Why would an example program take 228ms? Z$ ./example/run --name='abc def' Unknown command "def" for "example". Try -…

Here is one of your empty argument being thrown away instead of respected bugs:

* https://github.com/spf13/cobra/blob/6dec1ae26659a130bdb4c985...

I could explain the single-quote argument quoting error if you were running it on Windows. The Go runtime library does not provide single-quoting on Windows. At all. (This is historically the behaviour of C runtime libraries on Windows, too.) It should be using a proper argument vector and not doing its own command-line parsing on other platforms, though.

* https://cs.opensource.google/go/go/+/master:src/os/exec_wind...

* https://cs.opensource.google/go/go/+/master:src/os/proc.go;l...

Re: Fang, the CLI Starter Kit

#29

Stubborn complaint (and maybe a hot take): I dislike CLIs that try to be overly pretty. I don't receive any tangible benefit as the user from the "fancy" (their words) help output. I'd much rather simple plain text output that looks like all the other tools I already use.

agreed, plain text is more scriptable too. Let me pipe it into awk!

A lot of the fancy CLIs I use have a `--json` option that gives the user the chance to pipe output to eg jq and process it there. I find that a good alternative to running stuff through cut, sed or awk before processing.
Post reply on HN