Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
daveads committed Oct 4, 2024
1 parent 0a77dca commit ad4e4fd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
34 changes: 28 additions & 6 deletions cmd/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -44,6 +43,7 @@ func init() {
delCmd.Flags().StringVar(&keygenext.Environment, "environment", "", "your keygen.sh environment identifier [$KEYGEN_ENVIRONMENT=<id>]")
delCmd.Flags().StringVar(&keygenext.APIURL, "host", "", "the host of the keygen server [$KEYGEN_HOST=<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]")

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
6 changes: 6 additions & 0 deletions cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func tagArgs(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("tag is required")
}

return nil
}

Expand All @@ -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
}

Expand All @@ -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
}
5 changes: 5 additions & 0 deletions cmd/untag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
5 changes: 5 additions & 0 deletions cmd/yank.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

0 comments on commit ad4e4fd

Please sign in to comment.