Skip to content

Commit

Permalink
Change the format of list command
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Mar 13, 2017
1 parent 5fb9718 commit 07abeec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strings"

"github.com/fatih/color"
"github.com/knqyf263/pet/config"
Expand Down Expand Up @@ -34,15 +35,24 @@ func list(cmd *cobra.Command, args []string) error {
}

for _, snippet := range snippets.Snippets {
description := runewidth.FillRight(runewidth.Truncate(snippet.Description, col, "..."), col)
command := runewidth.Truncate(snippet.Command, 100-4-col, "...")

fmt.Fprintf(color.Output, "%s : %s\n",
color.GreenString(description), color.YellowString(command))
if config.Flag.OneLine {
description := runewidth.FillRight(runewidth.Truncate(snippet.Description, col, "..."), col)
command := runewidth.Truncate(snippet.Command, 100-4-col, "...")
fmt.Fprintf(color.Output, "%s : %s\n",
color.GreenString(description), color.YellowString(command))
} else {
fmt.Fprintf(color.Output, "%12s %s\n",
color.GreenString("Description:"), snippet.Description)
fmt.Fprintf(color.Output, "%12s %s\n",
color.YellowString(" Command:"), snippet.Command)
fmt.Println(strings.Repeat("-", 30))
}
}
return nil
}

func init() {
RootCmd.AddCommand(listCmd)
listCmd.Flags().BoolVarP(&config.Flag.OneLine, "oneline", "", false,
`Display snippets in one line`)
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type FlagConfig struct {
Query string
Delimiter string
Upload bool
OneLine bool
}

func (cfg *Config) Load(file string) error {
Expand Down
Binary file modified doc/pet01.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 07abeec

Please sign in to comment.