Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Update the error message for the credentials generate command. (#285)
Browse files Browse the repository at this point in the history
The command defined in credential_generate.go reuses the bundleFileOrArg2 function from install.go. That function has a couple of install references embedded within it. (#285)

This PR introduces a new function for the credentials generate command with updated wording.

Fixes #282
  • Loading branch information
jeremyrickard authored Oct 16, 2018
1 parent afc1647 commit 55316c9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/duffle/credential_generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -38,7 +39,7 @@ func newCredentialGenerateCmd(out io.Writer) *cobra.Command {
Short: "generate a credentialset from a bundle",
Long: credentialGenerateHelp,
RunE: func(cmd *cobra.Command, args []string) error {
bf, err := bundleFileOrArg2(args, bundleFile, out)
bf, err := getBundleFileFromCredentialsArg(args, bundleFile, out)
if err != nil {
return err
}
Expand Down Expand Up @@ -91,3 +92,17 @@ func genCredentialSet(name string, creds map[string]bundle.CredentialLocation) c

return cs
}

func getBundleFileFromCredentialsArg(args []string, bundleFile string, w io.Writer) (string, error) {
switch {
case len(args) < 1:
return "", errors.New("This command requires at least one argument: NAME (name for the credentialset). It also requires a BUNDLE (CNAB bundle name) or file (using -f)\nValid inputs:\n\t$ duffle credentials generate NAME BUNDLE\n\t$ duffle credentials generate NAME -f path-to-bundle.json")
case len(args) == 2 && bundleFile != "":
return "", errors.New("please use either -f or specify a BUNDLE, but not both")
case len(args) < 2 && bundleFile == "":
return "", errors.New("required arguments are NAME (name for the credentialset) and BUNDLE (CNAB bundle name) or file")
case len(args) == 2:
return getBundleFile(args[1])
}
return bundleFile, nil
}

0 comments on commit 55316c9

Please sign in to comment.