Caddy: Toward a more robust, consistent CLI

Created on 10 Nov 2015  路  12Comments  路  Source: caddyserver/caddy

Caddy's CLI has kind of been hacked together as the project expanded (quite rapidly) over the last few months. With 0.8, we have more flags than ever before and support for short Caddyfile as unflagged arguments.

Was chatting with @spf13 and he had some excellent suggestions for improving the CLI, by putting common functions behind a command. In other words, instead of slopping together caddy browse [and any number of other directives...], we can put it behind a command like caddy quick browse. It kind of frees up the parse space, I guess, and makes possible commands like caddy version or caddy revoke, without conflicting with directives.

The cobra library would be good for this. It also implements POSIX-compliant flags/options.

Would have to work out the details or go through a proposal before merging the changes (since they'd probably be breaking -- which is fine, we're not 1.0 yet).

Any takers?

feature request

All 12 comments

I would love to tackle this. I'll start looking at it tonight.

I want to help also. Maybe code it up / design it together?

@spf13 I would absolutely love that. Want to coordinate things over at Gophers Slack?

Sounds good

For reference, @spf13 has done a nice job porting Caddy over to Cobra a while ago: https://github.com/spf13/caddy/commit/6a9a368c71966fb990f1c63a6b50681d10b03d58

With all the LE stuff lately my time has been focused on getting that right, but I do want to revisit this before we lock into 1.0 since I think Cobra is the way to go.

For nearly the same reasoning as in #862, I think I'm going to pass on this for now; most users seem to like using Caddyfile directives as subcommands and the CLI hasn't been a reported pain point at all; plus what we have now is nice and lightweight and very easily pluggable. (I'm using cobra for a couple other projects right now and am liking it -- but I'm not sure it's worth changing Caddy up at this point just for the sake of using it.)

I'll put my $0.02 here. In order to make Caddy more "unix-like", I'd push for the github.com/ogier/pflag package... :)

@mholt
Hi, I'm trying v2 and couldn't even start program at first, til I found subcommands in source code. :sob:
Any thoughts on this for v2? I couldn't find it in v2 milestone. Do you mind if I add this?

@aca Yikes, that doesn't sound like a great experience. I wouldn't wish anyone to use v2 without first checking out the getting started guide on the readme or the docs which explain the CLI here: https://github.com/caddyserver/caddy/wiki/v2:-Documentation#command-line-interface

Caddy 2 has a proper CLI now, but it lacks in-command documentation (i.e. caddy -h and getting help/documentation for the individual subcommands). We should add this. Doesn't have to be fancy -- we don't need another dependency for this, just a "help" subcommand probably. Would be happy to discuss an implementation and then review a PR!

@mholt
Thanks, I understand that you don't want to add dependancies. But if caddy has a plan for more complicated configuration with flags, I believe it would be better to use libraries like pflag to follow gnu conventions for cli interface.

For now, I think It will be much better if there's cli interface just like 'go'.

  • "help" subcommand.
    I think 'caddy help start' is better than 'caddy start -h'. Later needs help flag handling for every subcommand. Just implementing help subcommand is simpler solution I believe.
  • verbose description in usageString.
    禄 caddy usage: caddy <command> [<args>]
    At least, listing summary of subcommands would be better than this. It would be nice if I have chance to contribute to this great project.

@aca I've been pretty happy with the standard flag package for the CLI. Gnu style flags work with it as well.

I agree a help subcommand would be best. Want to implement it and submit a PR? Of course we can continue to discuss along the way.

And yes a list of subcommands would also be great. That sounds good.

@mholt
I will give it a try! Wait for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

billop picture billop  路  3Comments

crvv picture crvv  路  3Comments

kilpatty picture kilpatty  路  3Comments

PhilmacFLy picture PhilmacFLy  路  3Comments

dafanasiev picture dafanasiev  路  3Comments