Skip to content

Inspired by Cobra. Cobra is a library for creating powerful modern CLI applications. "action" can be used to create a more fine-grained behavior of a command.

License

Notifications You must be signed in to change notification settings

shipengqi/action

Repository files navigation

action

Inspired by Cobra. Cobra is a library for creating powerful modern CLI applications. "action" can be used to create a more fine-grained behavior of a command.

Test Status Codecov Release License

Getting Started

cmd := &cobra.Command{
    Use:   "example-cmd",
    Short: "A sample command.",
    RunE: func(cmd *cobra.Command, args []string) error {
        act := &action.Action{
            Name: "example-action",
            Run:  func(act *action.Action) error { return nil },
        }
        
        _ = act.AddAction(
            newSubAction1(),
            newSubAction2(),
        )

        act.Execute()
    },
}

func newSubAction1() *action.Action {
    return &action.Action{
        Name: "sub-action1", 
        Executable: func(act *action.Action) bool {
            // do something
            return true
        },
        Run:  func(act *action.Action) error { return nil },
    }
}

func newSubAction2() *action.Action {
    return &action.Action{
        Name: "sub-action2",
        Executable: func(act *action.Action) bool {
            // do something
            return false
        },
        Run:  func(act *action.Action) error { return nil },
    }
}
  • Executable: whether is an executable action.
  • action.Execute() will find the first executable action of the root action and execute it. If no executable action can be found, run the current action.

Documentation

You can find the docs at go docs.

🔋 JetBrains OS licenses

action had been being developed with GoLand under the free JetBrains Open Source license(s) granted by JetBrains s.r.o., hence I would like to express my thanks here.

JetBrains Logo (Main) logo.

About

Inspired by Cobra. Cobra is a library for creating powerful modern CLI applications. "action" can be used to create a more fine-grained behavior of a command.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages