-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for functional commands (#12)
* feat: add support for functional commands * update readme * remove unused line
- Loading branch information
1 parent
781495c
commit b2cd8fd
Showing
5 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cli | ||
|
||
//FunctionalCommand is any simple function that returns an optional error | ||
type FunctionalCommand func() error | ||
|
||
//FunctionalCommandWrapper an adapter to support running functional commands | ||
type FunctionalCommandWrapper struct { | ||
Command FunctionalCommand | ||
} | ||
|
||
//Run executes the wrapped functional command | ||
func (c *FunctionalCommandWrapper) Run() error { | ||
return c.Command() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/LucasCarioca/gocli/cli" | ||
) | ||
|
||
func functionalCommand() error { | ||
fmt.Println("This is the default functional command") | ||
return nil | ||
} | ||
|
||
func functionalCommand2() error { | ||
fmt.Println("This is another functional command") | ||
return nil | ||
} | ||
|
||
func main() { | ||
app := cli.NewApp(functionalCommand) | ||
app.AddCommand("hello", functionalCommand2) | ||
app.AddCommand("inline", func() error { | ||
fmt.Println("This command is created inline") | ||
return nil | ||
}) | ||
app.Run() | ||
} |