Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refine cmd cli interactive output #958

Merged
merged 1 commit into from
Mar 25, 2024
Merged
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 kusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {

if err := command.Execute(); err != nil {
// Pretty-print the error and exit with an error.
pretty.Error.Println(err.Error())
pretty.ErrorT.Println(err.Error())
os.Exit(1)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/apply/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func Apply(
strings.ToLower(string(msg.OpResult)),
)
}
pterm.Success.WithWriter(out).Println(title)
pretty.SuccessT.WithWriter(out).Printfln(title)
progressbar.UpdateTitle(title)
progressbar.Increment()
ls.Count(changeStep.Action)
Expand All @@ -267,7 +267,7 @@ func Apply(
pterm.Bold.Sprint(changeStep.ID),
strings.ToLower(string(msg.OpResult)),
)
pterm.Error.WithWriter(out).Printf("%s\n", title)
pretty.ErrorT.WithWriter(out).Printf("%s\n", title)
default:
title := fmt.Sprintf("%s %s %s",
changeStep.Action.Ing(),
Expand Down Expand Up @@ -307,6 +307,7 @@ func Apply(
// wait for msgCh closed
wg.Wait()
// print summary
pterm.Println()
pterm.Fprintln(out, fmt.Sprintf("Apply complete! Resources: %d created, %d updated, %d deleted.", ls.created, ls.updated, ls.deleted))
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/destroy/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"kusionstack.io/kusion/pkg/engine/state"
"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/project"
"kusionstack.io/kusion/pkg/util/pretty"
"kusionstack.io/kusion/pkg/util/signals"
"kusionstack.io/kusion/pkg/workspace"
)
Expand Down Expand Up @@ -191,7 +192,7 @@ func (o *Options) destroy(planResources *apiv1.Intent, changes *models.Changes,
var deleted int

// progress bar, print dag walk detail
progressbar, err := pterm.DefaultProgressbar.WithTotal(len(changes.StepKeys)).Start()
progressbar, err := pterm.DefaultProgressbar.WithMaxWidth(0).WithTotal(len(changes.StepKeys)).Start()
if err != nil {
return err
}
Expand Down Expand Up @@ -231,7 +232,7 @@ func (o *Options) destroy(planResources *apiv1.Intent, changes *models.Changes,
strings.ToLower(string(msg.OpResult)),
)
}
pterm.Success.Println(title)
pretty.SuccessT.Println(title)
progressbar.UpdateTitle(title)
progressbar.Increment()
deleted++
Expand All @@ -241,7 +242,7 @@ func (o *Options) destroy(planResources *apiv1.Intent, changes *models.Changes,
pterm.Bold.Sprint(changeStep.ID),
strings.ToLower(string(msg.OpResult)),
)
pterm.Error.Printf("%s\n", title)
pretty.ErrorT.Printf("%s\n", title)
default:
title := fmt.Sprintf("%s %s %s",
changeStep.Action.Ing(),
Expand Down
11 changes: 3 additions & 8 deletions pkg/engine/operation/models/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,11 @@ func (p *Changes) AllUnChange() bool {
func (p *Changes) Summary(writer io.Writer) {
// Create a fork of the default table, fill it with data and print it.
// Data can also be generated and inserted later.
tableHeader := []string{fmt.Sprintf("Stack: %s", p.stack.Name), "ID", "Action"}
tableHeader := []string{fmt.Sprintf("Stack: %s\nID", p.stack.Name), "\nAction"}
tableData := pterm.TableData{tableHeader}

for i, step := range p.Values() {
itemPrefix := " * ├─"
if i == len(p.StepKeys)-1 {
itemPrefix = " * └─"
}

tableData = append(tableData, []string{itemPrefix, step.ID, step.Action.String()})
for _, step := range p.Values() {
tableData = append(tableData, []string{step.ID, step.Action.String()})
}

_ = pterm.DefaultTable.WithHasHeader().
Expand Down
Loading