Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with actions #47

Closed
szank opened this issue Jun 11, 2015 · 1 comment
Closed

Problem with actions #47

szank opened this issue Jun 11, 2015 · 1 comment

Comments

@szank
Copy link
Contributor

szank commented Jun 11, 2015

Hi, this is a simple program that doesn't seem to work as intended :
I have checked out v2.0.8 tag

package main

import (
    "fmt"
    "os"

    "gopkg.in/alecthomas/kingpin.v2"
)

func main() {
    app := kingpin.New("test", "testApp").Action(action).PreAction(preAction).Terminate(terminate)

    fmt.Println(app.Parse(os.Args[1:]))

}

func action(c *kingpin.ParseContext) error {
    fmt.Println("ACTION")
    return nil
}

func preAction(c *kingpin.ParseContext) error {
    fmt.Println("PRE ACTION")
    return nil
}

func terminate(code int) {
    fmt.Println("TERMINATE")
    os.Exit(code)
}

returns

ACTION
ACTION
 <nil>
@alecthomas
Copy link
Owner

Thanks for the catch. Copy and paste bug :(

FYI the termination handler will only execute if the parse fails, so you wouldn't expect to see TERMINATE in your example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants