Skip to content

Commit c07b0c2

Browse files
committed
chore(workflow-cli): format builds config print, optimize shortcut exec logs
1 parent 802fa7b commit c07b0c2

5 files changed

Lines changed: 52 additions & 34 deletions

File tree

cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var Shortcuts = map[string]string{
77
"info": "apps:info",
88
"login": "auth:login",
99
"logout": "auth:logout",
10-
"logs": "apps:logs",
10+
"logs": "ps:logs",
1111
"open": "apps:open",
1212
"pull": "builds:create",
1313
"rollback": "releases:rollback",

cmd/builds.go

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,10 @@ func (d *DryccCmd) BuildsFetch(appID string, version int, procfile, dryccpath, c
9393
return err
9494
}
9595
// Confirm again
96-
dockerfile := "Dockerfile"
97-
err = buildFetchConfirmAction(confirm, dockerfile, procfile, dryccpath, save)
96+
err = buildFetchConfirmAction(confirm, procfile, dryccpath, save)
9897
if err != nil {
9998
return err
10099
}
101-
if len(build.Dockerfile) != 0 {
102-
err := writeDockerfileToPath(d, dockerfile, build.Dockerfile, save)
103-
if err != nil {
104-
return fmt.Errorf("failed to write Dockerfile: %w", err)
105-
}
106-
}
107100

108101
if len(build.Procfile) != 0 {
109102
err := writeProcfileToPath(d, procfile, build.Procfile, save)
@@ -124,25 +117,13 @@ func (d *DryccCmd) BuildsFetch(appID string, version int, procfile, dryccpath, c
124117
return nil
125118
}
126119

127-
func writeDockerfileToPath(d *DryccCmd, dockerfile string, dockerinfo string, save bool) error {
128-
if save {
129-
os.Remove(dockerfile)
130-
err := os.WriteFile(dockerfile, []byte(dockerinfo), 0664)
131-
return err
132-
}
133-
d.Println("# Source:", dockerfile)
134-
d.Println(dockerinfo)
135-
return nil
136-
137-
}
138-
139120
func writeProcfileToPath(d *DryccCmd, procfile string, Procinfo map[string]string, save bool) error {
140121
if save {
141122
os.Remove(procfile)
142123
err := os.WriteFile(procfile, []byte(d.toYamlString(Procinfo, 2)), 0664)
143124
return err
144125
}
145-
d.Println("# Source:", procfile)
126+
d.Println("---\n# Source:", procfile)
146127
d.Println(d.toYamlString(Procinfo, 2))
147128
return nil
148129
}
@@ -180,7 +161,7 @@ func writeDryccfileToPath(d *DryccCmd, dryccpath string, dryccfile map[string]in
180161
return fmt.Errorf("failed to write env file: %w", err)
181162
}
182163
} else {
183-
d.Println("# Source:", envFilePath)
164+
d.Println("---\n# Source:", envFilePath)
184165
d.Println(content)
185166
}
186167
}
@@ -203,7 +184,7 @@ func writeDryccfileToPath(d *DryccCmd, dryccpath string, dryccfile map[string]in
203184
return fmt.Errorf("failed to write pipeline file: %w", err)
204185
}
205186
} else {
206-
d.Println("# Source:", filePath)
187+
d.Println("---\n# Source:", filePath)
207188
d.Println(string(yamlContent))
208189
}
209190
}
@@ -238,13 +219,13 @@ func buildConfirmAction(c *drycc.Client, appID string, procfileMap map[string]st
238219
return nil
239220
}
240221

241-
func buildFetchConfirmAction(confirm, dockerfile, procfile, dryccpath string, save bool) error {
222+
func buildFetchConfirmAction(confirm, procfile, dryccpath string, save bool) error {
242223

243224
if save && (confirm == "" || confirm != "yes") {
244225
// hint
245226
msg := fmt.Sprintf(" ! WARNING: Potentially Build Fetch Action\n"+
246-
" ! This operation will overwrite the current \x1b[1m%s\x1b[0m, \x1b[1m%s\x1b[0m or \x1b[1m%s\x1b[0m locally\n"+
247-
" ! To proceed, type \"yes\" !\n\n> ", dockerfile, procfile, dryccpath)
227+
" ! This operation will overwrite the current \x1b[1m%s\x1b[0m or \x1b[1m%s\x1b[0m locally\n"+
228+
" ! To proceed, type \"yes\" !\n\n> ", procfile, dryccpath)
248229

249230
fmt.Print(msg)
250231
fmt.Scanln(&confirm)

cmd/config.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/drycc/controller-sdk-go/api"
1414
"github.com/drycc/controller-sdk-go/appsettings"
1515
"github.com/drycc/controller-sdk-go/config"
16-
"sigs.k8s.io/yaml"
1716
)
1817

1918
// ConfigInfo for an app
@@ -32,7 +31,12 @@ func (d *DryccCmd) ConfigInfo(appID string, ptype string, group string, version
3231
Group: make(map[string][]api.ConfigVar),
3332
Ptype: make(map[string]api.PtypeValue),
3433
}
34+
hasGlobalGroup := false
3535
for _, value := range sortConfigValues(config.Values) {
36+
if value.Group == "global" {
37+
hasGlobalGroup = true
38+
}
39+
3640
// display the selected or all
3741
if (ptype != "" && value.Ptype == ptype) ||
3842
(group != "" && value.Group == group) ||
@@ -70,11 +74,43 @@ func (d *DryccCmd) ConfigInfo(appID string, ptype string, group string, version
7074
return nil
7175
}
7276

73-
c, err := yaml.Marshal(cv)
74-
if err != nil {
75-
return err
77+
// Format and print the output
78+
79+
// print group
80+
for group, configVars := range cv.Group {
81+
d.Println("---\n# Group:", group)
82+
var content string
83+
for _, configVar := range configVars {
84+
content += fmt.Sprintf("%s=%v\n", configVar.Name, configVar.Value)
85+
}
86+
d.Println(content)
7687
}
77-
d.Println(string(c))
88+
// print ptype
89+
for ptype, ptypeValue := range cv.Ptype {
90+
d.Printf("---\n# Ptype %s config\n", ptype)
91+
92+
if len(ptypeValue.Env) > 0 {
93+
d.Println("## env")
94+
var content string
95+
for _, configVar := range ptypeValue.Env {
96+
content += fmt.Sprintf("%s=%v\n", configVar.Name, configVar.Value)
97+
}
98+
d.Println(content)
99+
}
100+
101+
if len(ptypeValue.Ref) > 0 {
102+
d.Println("## ref")
103+
var content string
104+
for _, ref := range ptypeValue.Ref {
105+
content += fmt.Sprintf("- %s\n", ref)
106+
}
107+
if hasGlobalGroup {
108+
content += fmt.Sprintf("- %s\n", "global")
109+
}
110+
d.Println(content)
111+
}
112+
}
113+
78114
return nil
79115
}
80116

cmd/shortcuts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ destroy -> apps:destroy
1212
info -> apps:info
1313
login -> auth:login
1414
logout -> auth:logout
15-
logs -> apps:logs
15+
logs -> ps:logs
1616
open -> apps:open
1717
pull -> builds:create
1818
rollback -> releases:rollback

drycc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ Shortcut commands, use 'drycc shortcuts' to see all:
8383
8484
create create a new application
8585
destroy destroy an application
86+
exec execute a command in a container
8687
info view information about the current app
87-
logs view aggregated log info for the app
88+
logs print the logs for a container
8889
open open a URL to the app in a browser
8990
pull imports an image and deploys as a new release
9091
run run a command in an ephemeral app container

0 commit comments

Comments
 (0)