Skip to content
Myr

Update README.md (#1154)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

I found this through a comment on an issue and thought this might save someone some time looking through the code. fixes #1148

authored by Diana Flach · committed by GitHub · parent 207dc47 · Browse files · 1 file+31 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+31 added−0 removed

  • other:+31 added−0 removed

1 file+31 added−0 removed

modified:README.md+31 added
310 unmodified lines
311 },312}313```314315### Returning and handling errors316317If you wish to return an error to the caller of a command, `RunE` can be used.318319```go320package cmd321322import (323 "fmt"324325 "github.com/spf13/cobra"326)327328func init() {329 rootCmd.AddCommand(tryCmd)330}331332var tryCmd = &cobra.Command{333 Use: "try",334 Short: "Try and possibly fail at something",335 RunE: func(cmd *cobra.Command, args []string) error {336 err := someFunc()337 if err := nil {338 return err339 }340 },341}342```343344The error can then be caught at the execute function call.345346## Working with Flags347348Flags provide modifiers to control how the action command operates.349
420 unmodified lines