Skip to content

Commit

Permalink
issue #5: implement stderr command
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Apr 23, 2021
1 parent 2b330b5 commit 31d826e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/cmd/demo/stderr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package demo

import (
"strings"

"github.com/spf13/cobra"
)

// Stderr returns a demo cobra.Command to write to the stderr.
//
// $ go run main.go stderr [message]
// $ go run main.go stderr [message] >/dev/null
// $ go run main.go stderr [message] 2>/dev/null
//
func Stderr() *cobra.Command {
command := cobra.Command{
Use: "stderr",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
args = []string{cmd.Name(), "content"}
}
cmd.PrintErrln(strings.Join(args, " "))
},
}

return &command
}
1 change: 1 addition & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func New() *cobra.Command {
/* configure instance */
command.AddCommand(
demo.Panic(),
demo.Stderr(),
demo.Stdout(),
)

Expand Down

0 comments on commit 31d826e

Please sign in to comment.