Skip to content

Commit

Permalink
Merge pull request #11 from dbalan/echo_show_merge
Browse files Browse the repository at this point in the history
Merge echo and show commands together.
  • Loading branch information
dbalan committed Mar 15, 2018
2 parents 3358e2b + 62c9aeb commit 1d8417b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 58 deletions.
54 changes: 0 additions & 54 deletions cmd/echo.go

This file was deleted.

15 changes: 11 additions & 4 deletions cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,29 @@ import (
"github.com/spf13/cobra"
)

var body bool

// showCmd represents the show command
var showCmd = &cobra.Command{
Use: "show uid",
Short: "display the snippet",
Args: cobra.ExactArgs(1),
Use: "show uid",
Short: "display the snippet",
Args: cobra.ExactArgs(1),
PreRunE: ensureConfig,
Run: func(cmd *cobra.Command, args []string) {
dataStore := getDataStore()
snip, err := dataStore.Read(args[0])
errorGuard(err, "reading snippet failed")
fmt.Printf(fancySnippet(snip))
if body {
fmt.Printf(snip.Data)
} else {
fmt.Printf(fancySnippet(snip))
}
},
}

func init() {
rootCmd.AddCommand(showCmd)
showCmd.PersistentFlags().BoolVarP(&body, "body-only", "b", false, "show only snippet content")
}

func fancySnippet(s *pipetdata.Snippet) string {
Expand Down

0 comments on commit 1d8417b

Please sign in to comment.