mkideal / cli

CLI - A package for building command line app with go
MIT License
730 stars 43 forks source link

Global options #14

Closed suntong closed 8 years ago

suntong commented 8 years ago

Hi 仕晋,

I'll enhance my code-gen further before I write the wiki. Meanwhile, another question,

Does CLI support global options? By "global options" I mean the options supplied before the sub commands. E.g., both apt-get and git have options before the sub commands:

$ apt-get 
apt 1.2.10 (amd64)
Usage: apt-get [options] command
       apt-get [options] install|remove pkg1 [pkg2 ...]
       apt-get [options] source pkg1 [pkg2 ...]
...

$ git 
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
...

Any example that shows a sub command has global options and its own "private" options playing together?

On a very closely related question, when talking about global options, the most common request is for the application configuration, using something like -C config to override the defaults. Just like your 017-jsonfile example. My question is,

Would CLI allow the application to,

Would CLI allow the above layered approach? How much it can do at present?

Thanks

mkideal commented 8 years ago

Global options is unsupported at present. I'm trying to think. I will consider every one of your suggestions. I really appreciate you.

mkideal commented 8 years ago

Global options is supported now. see exmaple 027-global-option and commit b9abefb

suntong commented 8 years ago

thanks. will try tomorrow.

suntong commented 8 years ago

PERFECT!!

Even better that I anticipated.

Well done. Thanks a bunch!