From ad4e4fdbe0dd84d0a7b7de40394e2ccefb26b057 Mon Sep 17 00:00:00 2001 From: daveads Date: Fri, 4 Oct 2024 21:18:38 +0100 Subject: [PATCH] style --- cmd/del.go | 34 ++++++++++++++++++++++++++++------ cmd/publish.go | 5 +++++ cmd/tag.go | 6 ++++++ cmd/untag.go | 5 +++++ cmd/yank.go | 5 +++++ 5 files changed, 49 insertions(+), 6 deletions(-) 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 b3af926..6f58a90 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -119,12 +119,14 @@ func publishRun(cmd *cobra.Command, args []string) error { 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 } @@ -134,15 +136,18 @@ func publishRun(cmd *cobra.Command, args []string) error { 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 } fmt.Println(green("published:") + " release " + italic(release.ID)) + return nil } diff --git a/cmd/tag.go b/cmd/tag.go index 0f98e35..fec66d7 100644 --- a/cmd/tag.go +++ b/cmd/tag.go @@ -105,6 +105,7 @@ func tagArgs(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("tag is required") } + return nil } @@ -127,12 +128,14 @@ func tagRun(cmd *cobra.Command, args []string) error { 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 } @@ -144,15 +147,18 @@ func tagRun(cmd *cobra.Command, args []string) error { 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 } fmt.Println(green("tagged:") + " release " + italic(release.ID)) + return nil } diff --git a/cmd/untag.go b/cmd/untag.go index c92fb3b..053e49b 100644 --- a/cmd/untag.go +++ b/cmd/untag.go @@ -119,12 +119,14 @@ func untagRun(cmd *cobra.Command, args []string) error { 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 } @@ -136,15 +138,18 @@ func untagRun(cmd *cobra.Command, args []string) error { 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 } fmt.Println(green("untagged:") + " release " + italic(release.ID)) + return nil } diff --git a/cmd/yank.go b/cmd/yank.go index bab76a9..2c6c595 100644 --- a/cmd/yank.go +++ b/cmd/yank.go @@ -119,12 +119,14 @@ func yankRun(cmd *cobra.Command, args []string) error { 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 } @@ -134,15 +136,18 @@ func yankRun(cmd *cobra.Command, args []string) error { 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 } fmt.Println("yanked release " + italic(release.ID)) + return nil }