Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #751 from silvin-lubecki/remove-useless-inspect-flags
Browse files Browse the repository at this point in the history
Remove extra flags on docker app inspect command
  • Loading branch information
silvin-lubecki authored Nov 19, 2019
2 parents a04e9b3 + fb411ac commit 6c2b173
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
33 changes: 3 additions & 30 deletions internal/commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const inspectExample = `- $ docker app inspect my-running-app
type inspectOptions struct {
credentialOptions
cliopts.InstallerContextOptions
pretty bool
orchestrator string
kubeNamespace string
pretty bool
}

func inspectCmd(dockerCli command.Cli) *cobra.Command {
Expand All @@ -40,19 +38,12 @@ func inspectCmd(dockerCli command.Cli) *cobra.Command {
},
}
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Pretty print the output")
cmd.Flags().StringVar(&opts.orchestrator, "orchestrator", "", "Orchestrator where the App is running on (swarm, kubernetes)")
cmd.Flags().StringVar(&opts.kubeNamespace, "namespace", "default", "Kubernetes namespace in which to find the App")
opts.credentialOptions.addFlags(cmd.Flags())
opts.InstallerContextOptions.AddFlags(cmd.Flags())
return cmd
}

func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions) error {
orchestrator, err := getContextOrchestrator(dockerCli, inspectOptions.orchestrator)
if err != nil {
return err
}

defer muteDockerCli(dockerCli)()
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
if err != nil {
Expand All @@ -63,11 +54,6 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
return err
}

orchestratorName, ok := installation.Parameters[internal.ParameterOrchestratorName].(string)
if !ok || orchestratorName == "" {
orchestratorName = string(orchestrator)
}

creds, err := prepareCredentialSet(installation.Bundle, inspectOptions.CredentialSetOpts(dockerCli, credentialStore)...)
if err != nil {
return err
Expand All @@ -94,7 +80,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
}

if inspectOptions.pretty {
if err := inspect.Inspect(os.Stdout, installation, "pretty", orchestratorName); err != nil {
if err := inspect.Inspect(os.Stdout, installation, "pretty"); err != nil {
return err
}
fmt.Fprint(os.Stdout, buf.String())
Expand All @@ -107,7 +93,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
AppInfo inspect.AppInfo `json:",omitempty"`
Services interface{} `json:",omitempty"`
}{
inspect.GetAppInfo(installation, orchestratorName),
inspect.GetAppInfo(installation),
statusJSON,
}, "", " ")
if err != nil {
Expand All @@ -118,19 +104,6 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
return nil
}

func getContextOrchestrator(dockerCli command.Cli, orchestratorFlag string) (command.Orchestrator, error) {
var orchestrator command.Orchestrator
orchestrator, _ = command.NormalizeOrchestrator(orchestratorFlag)
if string(orchestrator) == "" {
orchestrator, err := dockerCli.StackOrchestrator("")
if err != nil {
return "", err
}
return orchestrator, nil
}
return orchestrator, nil
}

func hasAction(bndl *bundle.Bundle, actionName string) bool {
for key := range bndl.Actions {
if key == actionName {
Expand Down
15 changes: 7 additions & 8 deletions internal/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ type AppInfo struct {
Parameters map[string]interface{} `yaml:"Parameters,omitempty" json:"Parameters,omitempty"`
}

func Inspect(out io.Writer, installation *store.Installation, outputFormat string, cliDefinedOrchestrator string) error {
func Inspect(out io.Writer, installation *store.Installation, outputFormat string) error {
// Collect all the relevant information about the application
appInfo := GetAppInfo(installation, cliDefinedOrchestrator)
appInfo := GetAppInfo(installation)
return printAppInfo(out, appInfo, outputFormat)
}

func GetAppInfo(installation *store.Installation, cliDefinedOrchestrator string) AppInfo {
orchestrator := getOrchestrator(installation.Claim, cliDefinedOrchestrator)
func GetAppInfo(installation *store.Installation) AppInfo {
return AppInfo{
Installation: Installation{
Name: installation.Name,
Expand All @@ -86,7 +85,7 @@ func GetAppInfo(installation *store.Installation, cliDefinedOrchestrator string)
Revision: installation.Revision,
LastAction: installation.Result.Action,
Result: installation.Result.Status,
Orchestrator: orchestrator,
Orchestrator: getOrchestrator(installation.Claim),
},
Application: Application{
Name: installation.Bundle.Name,
Expand Down Expand Up @@ -232,11 +231,11 @@ func printSection(out io.Writer, len int, printer func(io.Writer), headers ...st
w.Flush()
}

func getOrchestrator(claim claim.Claim, cliDefaultOrchestrator string) string {
if orchestrator, ok := claim.Parameters[internal.ParameterOrchestratorName]; ok && orchestrator != "" {
func getOrchestrator(claim claim.Claim) string {
if orchestrator, ok := claim.Parameters[internal.ParameterOrchestratorName]; ok && orchestrator != nil {
return orchestrator.(string)
}
return cliDefaultOrchestrator
return ""
}

func removeDockerAppParameters(parameters map[string]interface{}) map[string]interface{} {
Expand Down
4 changes: 2 additions & 2 deletions internal/inspect/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func getInstallation() store.Installation {
"com.docker.app.args": "{}",
"com.docker.app.inspect-format": "json",
"com.docker.app.kubernetes-namespace": "default",
"com.docker.app.orchestrator": "",
"com.docker.app.orchestrator": "swarm",
"com.docker.app.render-format": "yaml",
"com.docker.app.share-registry-creds": false,
"port": "8080",
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestInspect(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
var out bytes.Buffer
err := Inspect(&out, &i, testCase.format, "swarm")
err := Inspect(&out, &i, testCase.format)
assert.NilError(t, err)
golden.Assert(t, out.String(), fmt.Sprintf("inspect-app-%s.golden", testCase.name))
})
Expand Down

0 comments on commit 6c2b173

Please sign in to comment.