Giter Club home page Giter Club logo

cli's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

fossabot

cli's Issues

Add support to build commands without a constructor.

Is your feature request related to a problem? Please describe.
Add support to build commands without a constructor.

So I want to create a command like this:

var RootCommand = &cli.Command{
    Name:             "programName",
    ShortDescription: "rootCommand Description",
    LongDescription:  "rootCommand Long Description",
    Run: func(c *cli.Command) error {
        c.Usage()

        return nil
    },
    
}

err := RootCommand.Execute()
if err != nil {
    _ = RootCommand.Logger().Log("ERROR:", err)
}

This now is not working and produces the following stacktrace:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x112f879]

goroutine 6 [running]:
testing.tRunner.func1(0xc00009e200)
        /usr/local/go/src/testing/testing.go:792 +0x387
panic(0x1179fc0, 0x12e0190)
        /usr/local/go/src/runtime/panic.go:513 +0x1b9
text/template.errRecover(0xc0000b5d60)
        /usr/local/go/src/text/template/exec.go:160 +0x1d0
panic(0x1179fc0, 0x12e0190)
        /usr/local/go/src/runtime/panic.go:513 +0x1b9
text/template.(*state).walk(0xc0000b5ce0, 0x118cc20, 0xc0000cc000, 0x99, 0x11d1a80, 0xc00000e4e0)
        /usr/local/go/src/text/template/exec.go:269 +0x3b9
text/template.(*state).walk(0xc0000b5ce0, 0x118cc20, 0xc0000cc000, 0x99, 0x11d18c0, 0xc00000e4b0)
        /usr/local/go/src/text/template/exec.go:262 +0x142
text/template.(*Template).execute(0xc00004a780, 0x0, 0x0, 0x118cc20, 0xc0000cc000, 0x0, 0x0)
        /usr/local/go/src/text/template/exec.go:217 +0x215
text/template.(*Template).Execute(0xc00004a780, 0x0, 0x0, 0x118cc20, 0xc0000cc000, 0x0, 0x1)
        /usr/local/go/src/text/template/exec.go:200 +0x53
github.com/goombaio/cli.(*Command).Usage(0xc0000a80a0)
        /Users/raul/Projects/goombaio/cli/usage.go:88 +0x493
github.com/goombaio/cli_test.TestCommand_withoutConstructor.func1(0xc0000a80a0, 0x0, 0x0)
        /Users/raul/Projects/goombaio/cli/command_test.go:49 +0x2b
github.com/goombaio/cli.(*Command).Execute(0xc0000a80a0, 0xc0000a80a0, 0x5baa565a)
        /Users/raul/Projects/goombaio/cli/command.go:204 +0xf2
github.com/goombaio/cli_test.TestCommand_withoutConstructor(0xc00009e200)
        /Users/raul/Projects/goombaio/cli/command_test.go:55 +0x10a
testing.tRunner(0xc00009e200, 0x11b1530)
        /usr/local/go/src/testing/testing.go:827 +0xbf
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:878 +0x353
FAIL    github.com/goombaio/cli 0.014s
?       github.com/goombaio/cli/examples/simple [no test files]
?       github.com/goombaio/cli/examples/simple_command [no test files]
make: *** [test] Error 1

Add support to ignore the long flag

Add support to ignore the long flag

For example I would like to define a flag -v but --verbose should not work.
Also in the Usage must be reflected like this:

-h, -help    Show help message
-v           Verbose mode enabled
    -force   Force an operation

Support for long flags with two dashes.

Right now:

$ program -f             # works
$ program -force     # works
$ program --force   # doesn't work
  • The third case must be supported.
  • It is not clear but long flags with one dash should be? Read some docs about POSIX and GNU.

Add support to ignore the short flag

For example I would like to define a flag --force but -f should not work.
Also in the Usage must be reflected like this:

-h, --help    Show help message
    --force   Force an operation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.