Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME := mani
PACKAGE := github.com/alajmo/$(NAME)
DATE := $(shell date +"%Y %B %d")
GIT := $(shell [ -d .git ] && git rev-parse --short HEAD)
VERSION := v0.31.2
VERSION := v0.32.0

default: build

Expand Down
4 changes: 2 additions & 2 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ executed in each directory.`,
cmd.Flags().BoolVarP(&runFlags.Cwd, "cwd", "k", false, "use current working directory")
cmd.Flags().BoolVarP(&runFlags.All, "all", "a", false, "target all projects")

cmd.Flags().StringVarP(&runFlags.Output, "output", "o", "", "set output format [stream|table|markdown|html]")
cmd.Flags().StringVarP(&runFlags.Output, "output", "o", "", "set output format [stream|table|markdown|html|json|yaml]")
err := cmd.RegisterFlagCompletionFunc("output", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if *configErr != nil {
return []string{}, cobra.ShellCompDirectiveDefault
}
valid := []string{"table", "markdown", "html"}
valid := []string{"stream", "table", "markdown", "html", "json", "yaml"}
return valid, cobra.ShellCompDirectiveDefault
})
core.CheckIfError(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func listCmd(config *dao.Config, configErr *error) *cobra.Command {
})
core.CheckIfError(err)

cmd.PersistentFlags().StringVarP(&listFlags.Output, "output", "o", "table", "set output format [table|markdown|html]")
cmd.PersistentFlags().StringVarP(&listFlags.Output, "output", "o", "table", "set output format [table|markdown|html|json|yaml]")
err = cmd.RegisterFlagCompletionFunc("output", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if *configErr != nil {
return []string{}, cobra.ShellCompDirectiveDefault
}

valid := []string{"table", "markdown", "html"}
valid := []string{"table", "markdown", "html", "json", "yaml"}
return valid, cobra.ShellCompDirectiveDefault
})
core.CheckIfError(err)
Expand Down
55 changes: 40 additions & 15 deletions cmd/list_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,47 @@ func listProjects(

if len(projects) == 0 {
fmt.Println("No matching projects found")
} else {
theme.Table.Border.Rows = core.Ptr(false)
theme.Table.Header.Format = core.Ptr("t")

options := print.PrintTableOptions{
Output: listFlags.Output,
Theme: *theme,
Tree: listFlags.Tree,
AutoWrap: true,
OmitEmptyRows: false,
OmitEmptyColumns: true,
Color: *theme.Color,
return
}

// Handle JSON/YAML output
if listFlags.Output == "json" || listFlags.Output == "yaml" {
outputProjects := make([]print.ProjectOutput, len(projects))
for i, p := range projects {
outputProjects[i] = print.ProjectOutput{
Name: p.Name,
Path: p.Path,
RelPath: p.RelPath,
Description: p.Desc,
URL: p.URL,
Tags: p.Tags,
}
}

if listFlags.Output == "json" {
err = print.PrintListJSON(outputProjects, os.Stdout)
} else {
err = print.PrintListYAML(outputProjects, os.Stdout)
}
core.CheckIfError(err)
return
}

fmt.Println()
print.PrintTable(projects, options, projectFlags.Headers, []string{}, os.Stdout)
fmt.Println()
// Table/Markdown/HTML output
theme.Table.Border.Rows = core.Ptr(false)
theme.Table.Header.Format = core.Ptr("t")

options := print.PrintTableOptions{
Output: listFlags.Output,
Theme: *theme,
Tree: listFlags.Tree,
AutoWrap: true,
OmitEmptyRows: false,
OmitEmptyColumns: true,
Color: *theme.Color,
}

fmt.Println()
print.PrintTable(projects, options, projectFlags.Headers, []string{}, os.Stdout)
fmt.Println()
}
74 changes: 44 additions & 30 deletions cmd/list_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,62 @@ func listTags(
theme, err := config.GetTheme(listFlags.Theme)
core.CheckIfError(err)

theme.Table.Border.Rows = core.Ptr(false)
theme.Table.Header.Format = core.Ptr("t")

options := print.PrintTableOptions{
Output: listFlags.Output,
Theme: *theme,
Tree: listFlags.Tree,
AutoWrap: true,
OmitEmptyRows: false,
OmitEmptyColumns: true,
Color: *theme.Color,
}

allTags := config.GetTags()

var tagsToUse []string
if len(args) > 0 {
foundTags := core.Intersection(args, allTags)

// Could not find one of the provided tags
if len(foundTags) != len(args) {
core.CheckIfError(&core.TagNotFound{Tags: args})
}
tagsToUse = foundTags
} else {
tagsToUse = allTags
}

tags, err := config.GetTagAssocations(foundTags)
core.CheckIfError(err)
tags, err := config.GetTagAssocations(tagsToUse)
core.CheckIfError(err)

if len(tags) == 0 {
fmt.Println("No tags")
} else {
fmt.Println()
print.PrintTable(tags, options, tagFlags.Headers, []string{}, os.Stdout)
fmt.Println()
if len(tags) == 0 {
fmt.Println("No tags")
return
}

// Handle JSON/YAML output
if listFlags.Output == "json" || listFlags.Output == "yaml" {
outputTags := make([]print.TagOutput, len(tags))
for i, t := range tags {
outputTags[i] = print.TagOutput{
Name: t.Name,
Projects: t.Projects,
}
}
} else {
tags, err := config.GetTagAssocations(allTags)
core.CheckIfError(err)
if len(tags) == 0 {
fmt.Println("No tags")

if listFlags.Output == "json" {
err = print.PrintListJSON(outputTags, os.Stdout)
} else {
fmt.Println("")
print.PrintTable(tags, options, tagFlags.Headers, []string{}, os.Stdout)
fmt.Println("")
err = print.PrintListYAML(outputTags, os.Stdout)
}
core.CheckIfError(err)
return
}

// Table/Markdown/HTML output
theme.Table.Border.Rows = core.Ptr(false)
theme.Table.Header.Format = core.Ptr("t")

options := print.PrintTableOptions{
Output: listFlags.Output,
Theme: *theme,
Tree: listFlags.Tree,
AutoWrap: true,
OmitEmptyRows: false,
OmitEmptyColumns: true,
Color: *theme.Color,
}

fmt.Println()
print.PrintTable(tags, options, tagFlags.Headers, []string{}, os.Stdout)
fmt.Println()
}
53 changes: 38 additions & 15 deletions cmd/list_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,45 @@ func listTasks(

if len(tasks) == 0 {
fmt.Println("No tasks")
} else {
theme.Table.Border.Rows = core.Ptr(false)
theme.Table.Header.Format = core.Ptr("t")

options := print.PrintTableOptions{
Output: listFlags.Output,
Theme: *theme,
Tree: listFlags.Tree,
AutoWrap: true,
OmitEmptyRows: false,
OmitEmptyColumns: true,
Color: *theme.Color,
return
}

// Handle JSON/YAML output
if listFlags.Output == "json" || listFlags.Output == "yaml" {
outputTasks := make([]print.TaskOutput, len(tasks))
for i, t := range tasks {
outputTasks[i] = print.TaskOutput{
Name: t.Name,
Description: t.Desc,
Spec: t.SpecData.Name,
Target: t.TargetData.Name,
}
}

if listFlags.Output == "json" {
err = print.PrintListJSON(outputTasks, os.Stdout)
} else {
err = print.PrintListYAML(outputTasks, os.Stdout)
}
core.CheckIfError(err)
return
}

fmt.Println()
print.PrintTable(tasks, options, taskFlags.Headers, []string{}, os.Stdout)
fmt.Println()
// Table/Markdown/HTML output
theme.Table.Border.Rows = core.Ptr(false)
theme.Table.Header.Format = core.Ptr("t")

options := print.PrintTableOptions{
Output: listFlags.Output,
Theme: *theme,
Tree: listFlags.Tree,
AutoWrap: true,
OmitEmptyRows: false,
OmitEmptyColumns: true,
Color: *theme.Color,
}

fmt.Println()
print.PrintTable(tasks, options, taskFlags.Headers, []string{}, os.Stdout)
fmt.Println()
}
4 changes: 2 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ The tasks are specified in a mani.yaml file along with the projects you can targ
cmd.Flags().BoolVarP(&runFlags.Edit, "edit", "e", false, "edit task")
cmd.Flags().Uint32P("forks", "f", 4, "maximum number of concurrent processes")

cmd.Flags().StringVarP(&runFlags.Output, "output", "o", "", "set output format [stream|table|markdown|html]")
cmd.Flags().StringVarP(&runFlags.Output, "output", "o", "", "set output format [stream|table|markdown|html|json|yaml]")
err := cmd.RegisterFlagCompletionFunc("output", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if *configErr != nil {
return []string{}, cobra.ShellCompDirectiveDefault
}

valid := []string{"stream", "table", "html", "markdown"}
valid := []string{"stream", "table", "html", "markdown", "json", "yaml"}
return valid, cobra.ShellCompDirectiveDefault
})
core.CheckIfError(err)
Expand Down
2 changes: 1 addition & 1 deletion core/dao/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Config) GetSpecList() ([]Spec, []ResourceErrors[Spec]) {
}

switch spec.Output {
case "", "table", "stream", "html", "markdown":
case "", "table", "stream", "html", "markdown", "json", "yaml":
default:
foundErrors = true
specError := ResourceErrors[Spec]{
Expand Down
2 changes: 1 addition & 1 deletion core/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type SpecOutputError struct {
}

func (c *SpecOutputError) Error() string {
return fmt.Sprintf("invalid output for spec `%s`, found `%s`, expected one of: stream, table, html, markdown", c.Name, c.Output)
return fmt.Sprintf("invalid output for spec `%s`, found `%s`, expected one of: stream, table, html, markdown, json, yaml", c.Name, c.Output)
}

type TargetNotFound struct {
Expand Down
20 changes: 20 additions & 0 deletions core/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ func (exec *Exec) Run(
}
print.PrintTable(data.Rows, options, data.Headers[0:1], data.Headers[1:], os.Stdout)
fmt.Println("")
case "json":
isParallel := tasks[0].SpecData.Parallel
results := exec.JSON(runFlags, "json", os.Stdout)
// Only print collected results if not parallel (parallel streams immediately)
if !isParallel {
err = PrintJSON(results, os.Stdout)
if err != nil {
return err
}
}
case "yaml":
isParallel := tasks[0].SpecData.Parallel
results := exec.JSON(runFlags, "yaml", os.Stdout)
// Only print collected results if not parallel (parallel streams immediately)
if !isParallel {
err = PrintYAML(results, os.Stdout)
if err != nil {
return err
}
}
default:
exec.Text(runFlags.DryRun, os.Stdout, os.Stderr)
}
Expand Down
Loading
Loading