Skip to content

Commit

Permalink
Add show ids in runn list command
Browse files Browse the repository at this point in the history
- Defaults to short trimmed ID, `--long` option to show the entire ID.
- `--long` option to show the full path.
  • Loading branch information
k1LoW committed Jul 27, 2023
1 parent cd4eed7 commit a5b8391
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var listCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"desc:", "if:", "steps:", "path"})
table.SetHeader([]string{"id:", "desc:", "if:", "steps:", "path"})
table.SetAutoWrapText(false)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoFormatHeaders(false)
Expand Down Expand Up @@ -77,11 +77,18 @@ var listCmd = &cobra.Command{
return err
}
for _, oo := range selected {
id := oo.ID()
if !flgs.Long {
id = id[:7]
}
desc := oo.Desc()
p := runn.ShortenPath(oo.BookPath())
p := oo.BookPath()
if !flgs.Long {
p = runn.ShortenPath(p)
}
c := strconv.Itoa(oo.NumberOfSteps())
ifCond := oo.If()
table.Append([]string{desc, ifCond, c, p})
table.Append([]string{id, desc, ifCond, c, p})
}

table.Render()
Expand All @@ -92,6 +99,7 @@ var listCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(listCmd)
listCmd.Flags().BoolVarP(&flgs.Long, "long", "l", false, flgs.Usage("Long"))
listCmd.Flags().BoolVarP(&flgs.SkipIncluded, "skip-included", "", false, flgs.Usage("SkipIncluded"))
listCmd.Flags().StringSliceVarP(&flgs.Vars, "var", "", []string{}, flgs.Usage("Vars"))
listCmd.Flags().StringSliceVarP(&flgs.Runners, "runner", "", []string{}, flgs.Usage("Runners"))
Expand Down
1 change: 1 addition & 0 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var floatRe = regexp.MustCompile(`^\-?[0-9.]+$`)

type Flags struct {
Debug bool `usage:"debug"`
Long bool `usage:"long format"`
FailFast bool `usage:"fail fast"`
SkipTest bool `usage:"skip \"test:\" section"`
SkipIncluded bool `usage:"skip running the included runbook by itself"`
Expand Down
5 changes: 5 additions & 0 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ type operator struct {
mu sync.Mutex
}

// ID returns id of runbook.
func (o *operator) ID() string {
return o.id
}

// Desc returns `desc:` of runbook.
func (o *operator) Desc() string {
return o.desc
Expand Down

0 comments on commit a5b8391

Please sign in to comment.