-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from gchiesa/61-support-for-list-rename-delete…
…-ska-configs feat: ska config command, package and output rendering
- Loading branch information
Showing
24 changed files
with
624 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/apex/log" | ||
"github.com/gchiesa/ska/pkg/skaffolder" | ||
"github.com/gchiesa/ska/pkg/util" | ||
"github.com/manifoldco/promptui" | ||
) | ||
|
||
type ConfigDeleteCmd struct { | ||
Name string `arg:"-n,--name,required" help:"The name of the named configuration to delete"` | ||
AutoApprove bool `arg:"-y,--auto-approve" help:"Skip the confirmation prompt"` | ||
} | ||
|
||
func (c *ConfigDeleteCmd) Execute(ctx context.Context) error { | ||
ska := skaffolder.NewSkaConfigTask(ctx.Value(configFolderPath("path")).(string)) | ||
|
||
lastUpdate, err := ska.QueryNamedConfigJSON(c.Name, "{.State.LastUpdate}") // nolint:govet | ||
if err != nil { | ||
return err | ||
} | ||
var result = make([]ConfigListResultItem, 0) | ||
result = append(result, ConfigListResultItem{ | ||
NamedConfig: c.Name, | ||
LastUpdate: lastUpdate, | ||
}) | ||
if !c.AutoApprove { | ||
output, err := util.RenderWithOutputFormat(result, "table") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(output)) | ||
p := promptui.Prompt{ | ||
Label: fmt.Sprintf("Do you really want to delete this configuration named %s", c.Name), | ||
IsConfirm: true, | ||
} | ||
response, err := p.Run() | ||
if err != nil { | ||
if errors.Is(err, promptui.ErrAbort) { | ||
log.Infof("You responded: %s, so not proceeding further.", response) | ||
return nil | ||
} | ||
return err | ||
} | ||
} | ||
if err := ska.DeleteConfig(c.Name); err != nil { | ||
return err | ||
} | ||
log.Infof("Deleted configuration: %s", c.Name) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/gchiesa/ska/pkg/skaffolder" | ||
"github.com/gchiesa/ska/pkg/util" | ||
) | ||
|
||
type ConfigListCmd struct { | ||
} | ||
|
||
type ConfigListResultItem struct { | ||
NamedConfig string `json:"NamedConfig" csv:"NamedConfig"` | ||
LastUpdate string `json:"LastUpdate" csv:"LastUpdate"` | ||
} | ||
|
||
func (c *ConfigListCmd) Execute(ctx context.Context) error { | ||
ska := skaffolder.NewSkaConfigTask(ctx.Value(configFolderPath("path")).(string)) | ||
|
||
namedConfigs, err := ska.ListNamedConfigs() | ||
if err != nil { | ||
return err | ||
} | ||
result := make([]ConfigListResultItem, 0, len(namedConfigs)) | ||
for _, namedConfig := range namedConfigs { | ||
lastUpdate, err := ska.QueryNamedConfigJSON(namedConfig, "{.State.LastUpdate}") // nolint:govet | ||
if err != nil { | ||
return err | ||
} | ||
result = append(result, ConfigListResultItem{ | ||
NamedConfig: namedConfig, | ||
LastUpdate: lastUpdate, | ||
}) | ||
} | ||
|
||
outputFormat := ctx.Value(consoleOutputFormat("output-format")).(string) | ||
output, err := util.RenderWithOutputFormat(result, outputFormat) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(output)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"github.com/gchiesa/ska/pkg/skaffolder" | ||
) | ||
|
||
type ConfigRenameCmd struct { | ||
Name string `arg:"-o,--name,required" help:"The name of the named configuration to rename"` | ||
NewName string `arg:"-n,--new-name,required" help:"The new name to give to the named configuration"` | ||
} | ||
|
||
func (c *ConfigRenameCmd) Execute(ctx context.Context) error { | ||
ska := skaffolder.NewSkaConfigTask(ctx.Value(configFolderPath("path")).(string)) | ||
|
||
if err := ska.RenameNamedConfig(c.Name, c.NewName); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/apex/log" | ||
) | ||
|
||
type ConfigCmd struct { | ||
*ConfigListCmd `arg:"subcommand:list"` | ||
*ConfigRenameCmd `arg:"subcommand:rename"` | ||
*ConfigDeleteCmd `arg:"subcommand:delete"` | ||
FolderPath string `arg:"-p,--path,required" help:"Local path where the .ska-config folder is located"` | ||
} | ||
|
||
type configFolderPath string | ||
|
||
func (c *ConfigCmd) Execute(ctx context.Context) error { | ||
configCtx := context.WithValue(ctx, configFolderPath("path"), c.FolderPath) | ||
switch { | ||
case c.ConfigListCmd != nil: | ||
if err := args.ConfigCmd.ConfigListCmd.Execute(configCtx); err != nil { | ||
log.Fatalf("error executing config list command: %v", err) | ||
} | ||
case c.ConfigRenameCmd != nil: | ||
if err := args.ConfigCmd.ConfigRenameCmd.Execute(configCtx); err != nil { | ||
log.Fatalf("error executing config rename command: %v", err) | ||
} | ||
case c.ConfigDeleteCmd != nil: | ||
if err := args.ConfigCmd.ConfigDeleteCmd.Execute(configCtx); err != nil { | ||
log.Fatalf("error executing config delete command: %v", err) | ||
} | ||
default: | ||
fmt.Println("no subcommand specified, please use the --help flag to check available commands") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.