diff --git a/cmd/del.go b/cmd/del.go index 6aa5bdd..43934c5 100644 --- a/cmd/del.go +++ b/cmd/del.go @@ -23,16 +23,15 @@ var ( Docs: https://keygen.sh/docs/cli/`, - Args: cobra.NoArgs, - RunE: delRun, - - // Encountering an error should not display usage + Args: cobra.NoArgs, + RunE: delRun, SilenceUsage: true, } ) type DeleteCommandOptions struct { Release string + Package string Artifact string NoAutoUpgrade bool } @@ -44,6 +43,7 @@ func init() { delCmd.Flags().StringVar(&keygenext.Environment, "environment", "", "your keygen.sh environment identifier [$KEYGEN_ENVIRONMENT=]") delCmd.Flags().StringVar(&keygenext.APIURL, "host", "", "the host of the keygen server [$KEYGEN_HOST=]") delCmd.Flags().StringVar(&delOpts.Release, "release", "", "the release identifier (required)") + delCmd.Flags().StringVar(&delOpts.Package, "package", "", "package identifier for the release") delCmd.Flags().StringVar(&delOpts.Artifact, "artifact", "", "the artifact identifier") delCmd.Flags().BoolVar(&delOpts.NoAutoUpgrade, "no-auto-upgrade", false, "disable automatic upgrade checks [$KEYGEN_NO_AUTO_UPGRADE=1]") @@ -114,14 +114,36 @@ func delRun(cmd *cobra.Command, args []string) error { var deletable interface { jsonapi.MarshalResourceIdentifier - Delete() error } + switch { case delOpts.Artifact != "": deletable = &keygenext.Artifact{ReleaseID: &delOpts.Release, ID: delOpts.Artifact} default: - deletable = &keygenext.Release{ID: delOpts.Release} + release := &keygenext.Release{ + ID: delOpts.Release, + PackageID: &delOpts.Package, + } + + if err := release.Get(); err != nil { + if e, ok := err.(*keygenext.Error); ok { + var code string + if e.Code != "" { + code = italic("(" + e.Code + ")") + } + + if e.Source != "" { + return fmt.Errorf("%s: %s %s %s", e.Title, e.Source, e.Detail, code) + } else { + return fmt.Errorf("%s: %s %s", e.Title, e.Detail, code) + } + } + + return err + } + + deletable = release } if err := deletable.Delete(); err != nil { diff --git a/cmd/publish.go b/cmd/publish.go index df8539d..6f58a90 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -21,16 +21,15 @@ var ( Docs: https://keygen.sh/docs/cli/`, - Args: cobra.NoArgs, - RunE: publishRun, - - // Encountering an error should not display usage + Args: cobra.NoArgs, + RunE: publishRun, SilenceUsage: true, } ) type PublishCommandOptions struct { Release string + Package string NoAutoUpgrade bool } @@ -41,6 +40,7 @@ func init() { publishCmd.Flags().StringVar(&keygenext.Environment, "environment", "", "your keygen.sh environment identifier [$KEYGEN_ENVIRONMENT=]") publishCmd.Flags().StringVar(&keygenext.APIURL, "host", "", "the host of the keygen server [$KEYGEN_HOST=]") publishCmd.Flags().StringVar(&publishOpts.Release, "release", "", "the release identifier (required)") + publishCmd.Flags().StringVar(&publishOpts.Package, "package", "", "package identifier for the release") publishCmd.Flags().BoolVar(&publishOpts.NoAutoUpgrade, "no-auto-upgrade", false, "disable automatic upgrade checks [$KEYGEN_NO_AUTO_UPGRADE=1]") if v, ok := os.LookupEnv("KEYGEN_ACCOUNT_ID"); ok { @@ -109,7 +109,25 @@ func publishRun(cmd *cobra.Command, args []string) error { } release := &keygenext.Release{ - ID: publishOpts.Release, + ID: publishOpts.Release, + PackageID: &publishOpts.Package, + } + + if err := release.Get(); err != nil { + if e, ok := err.(*keygenext.Error); ok { + var code string + if e.Code != "" { + code = italic("(" + e.Code + ")") + } + + if e.Source != "" { + return fmt.Errorf("%s: %s %s %s", e.Title, e.Source, e.Detail, code) + } else { + return fmt.Errorf("%s: %s %s", e.Title, e.Detail, code) + } + } + + return err } if err := release.Publish(); err != nil { diff --git a/cmd/tag.go b/cmd/tag.go index 95d46a7..fec66d7 100644 --- a/cmd/tag.go +++ b/cmd/tag.go @@ -22,16 +22,15 @@ var ( Docs: https://keygen.sh/docs/cli/`, - Args: tagArgs, - RunE: tagRun, - - // Encountering an error should not display usage + Args: tagArgs, + RunE: tagRun, SilenceUsage: true, } ) type TagCommandOptions struct { Release string + Package string NoAutoUpgrade bool } @@ -42,6 +41,7 @@ func init() { tagCmd.Flags().StringVar(&keygenext.Environment, "environment", "", "your keygen.sh environment identifier [$KEYGEN_ENVIRONMENT=]") tagCmd.Flags().StringVar(&keygenext.APIURL, "host", "", "the host of the keygen server [$KEYGEN_HOST=]") tagCmd.Flags().StringVar(&tagOpts.Release, "release", "", "the release identifier (required)") + tagCmd.Flags().StringVar(&tagOpts.Package, "package", "", "package identifier for the release") tagCmd.Flags().BoolVar(&tagOpts.NoAutoUpgrade, "no-auto-upgrade", false, "disable automatic upgrade checks [$KEYGEN_NO_AUTO_UPGRADE=1]") if v, ok := os.LookupEnv("KEYGEN_ACCOUNT_ID"); ok { @@ -118,10 +118,29 @@ func tagRun(cmd *cobra.Command, args []string) error { } release := &keygenext.Release{ - ID: tagOpts.Release, - Tag: &args[0], + ID: tagOpts.Release, + PackageID: &tagOpts.Package, + } + + if err := release.Get(); err != nil { + if e, ok := err.(*keygenext.Error); ok { + var code string + if e.Code != "" { + code = italic("(" + e.Code + ")") + } + + if e.Source != "" { + return fmt.Errorf("%s: %s %s %s", e.Title, e.Source, e.Detail, code) + } else { + return fmt.Errorf("%s: %s %s", e.Title, e.Detail, code) + } + } + + return err } + release.Tag = &args[0] + if err := release.Update(); err != nil { if e, ok := err.(*keygenext.Error); ok { var code string diff --git a/cmd/untag.go b/cmd/untag.go index 4663bec..053e49b 100644 --- a/cmd/untag.go +++ b/cmd/untag.go @@ -21,16 +21,15 @@ var ( Docs: https://keygen.sh/docs/cli/`, - Args: cobra.NoArgs, - RunE: untagRun, - - // Encountering an error should not display usage + Args: cobra.NoArgs, + RunE: untagRun, SilenceUsage: true, } ) type UntagCommandOptions struct { Release string + Package string NoAutoUpgrade bool } @@ -41,6 +40,7 @@ func init() { untagCmd.Flags().StringVar(&keygenext.Environment, "environment", "", "your keygen.sh environment identifier [$KEYGEN_ENVIRONMENT=]") untagCmd.Flags().StringVar(&keygenext.APIURL, "host", "", "the host of the keygen server [$KEYGEN_HOST=]") untagCmd.Flags().StringVar(&untagOpts.Release, "release", "", "the release identifier (required)") + untagCmd.Flags().StringVar(&untagOpts.Package, "package", "", "package identifier for the release") untagCmd.Flags().BoolVar(&untagOpts.NoAutoUpgrade, "no-auto-upgrade", false, "disable automatic upgrade checks [$KEYGEN_NO_AUTO_UPGRADE=1]") if v, ok := os.LookupEnv("KEYGEN_ACCOUNT_ID"); ok { @@ -109,10 +109,29 @@ func untagRun(cmd *cobra.Command, args []string) error { } release := &keygenext.Release{ - ID: untagOpts.Release, - Tag: nil, + ID: untagOpts.Release, + PackageID: &untagOpts.Package, + } + + if err := release.Get(); err != nil { + if e, ok := err.(*keygenext.Error); ok { + var code string + if e.Code != "" { + code = italic("(" + e.Code + ")") + } + + if e.Source != "" { + return fmt.Errorf("%s: %s %s %s", e.Title, e.Source, e.Detail, code) + } else { + return fmt.Errorf("%s: %s %s", e.Title, e.Detail, code) + } + } + + return err } + release.Tag = nil + if err := release.Update(); err != nil { if e, ok := err.(*keygenext.Error); ok { var code string diff --git a/cmd/yank.go b/cmd/yank.go index 1bd8ec5..2c6c595 100644 --- a/cmd/yank.go +++ b/cmd/yank.go @@ -21,16 +21,15 @@ var ( Docs: https://keygen.sh/docs/cli/`, - Args: cobra.NoArgs, - RunE: yankRun, - - // Encountering an error should not display usage + Args: cobra.NoArgs, + RunE: yankRun, SilenceUsage: true, } ) type YankCommandOptions struct { Release string + Package string NoAutoUpgrade bool } @@ -41,6 +40,7 @@ func init() { yankCmd.Flags().StringVar(&keygenext.Environment, "environment", "", "your keygen.sh environment identifier [$KEYGEN_ENVIRONMENT=]") yankCmd.Flags().StringVar(&keygenext.APIURL, "host", "", "the host of the keygen server [$KEYGEN_HOST=]") yankCmd.Flags().StringVar(&yankOpts.Release, "release", "", "the release identifier (required)") + yankCmd.Flags().StringVar(&yankOpts.Package, "package", "", "package identifier for the release") yankCmd.Flags().BoolVar(&yankOpts.NoAutoUpgrade, "no-auto-upgrade", false, "disable automatic upgrade checks [$KEYGEN_NO_AUTO_UPGRADE=1]") if v, ok := os.LookupEnv("KEYGEN_ACCOUNT_ID"); ok { @@ -109,7 +109,25 @@ func yankRun(cmd *cobra.Command, args []string) error { } release := &keygenext.Release{ - ID: yankOpts.Release, + ID: yankOpts.Release, + PackageID: &yankOpts.Package, + } + + if err := release.Get(); err != nil { + if e, ok := err.(*keygenext.Error); ok { + var code string + if e.Code != "" { + code = italic("(" + e.Code + ")") + } + + if e.Source != "" { + return fmt.Errorf("%s: %s %s %s", e.Title, e.Source, e.Detail, code) + } else { + return fmt.Errorf("%s: %s %s", e.Title, e.Detail, code) + } + } + + return err } if err := release.Yank(); err != nil {