-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the command "release exists". It checks if a release with give name exists. It can be used without a baur repository by setting the BAUR_POSTGRESQL_URL environment variable.
- Loading branch information
Showing
15 changed files
with
201 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ const ( | |
exitCodeError = 1 | ||
exitCodeAlreadyExist = 2 | ||
exitCodeTaskRunIsPending = 3 | ||
exitCodeNotExist = 4 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/simplesurance/baur/v3/internal/command/term" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var releaseExistsLongHelp = fmt.Sprintf(` | ||
Check if a release with a given name exists. | ||
The command can be run without access to the baur repository, by specifying | ||
the PostgreSQL URI via the environment variable %s. | ||
Exit Codes: | ||
%d - Success, release exists | ||
%d - Error | ||
%d - Release does not exist | ||
`, | ||
term.Highlight(envVarPSQLURL), | ||
exitCodeSuccess, | ||
exitCodeError, | ||
exitCodeNotExist, | ||
) | ||
|
||
type releaseExistsCmd struct { | ||
cobra.Command | ||
quiet bool | ||
} | ||
|
||
func init() { | ||
releaseCmd.AddCommand(&newReleaseExistsCmd().Command) | ||
} | ||
|
||
func newReleaseExistsCmd() *releaseExistsCmd { | ||
cmd := releaseExistsCmd{ | ||
Command: cobra.Command{ | ||
Use: "exists NAME", | ||
Short: "check if a release exists", | ||
Long: strings.TrimSpace(releaseExistsLongHelp), | ||
Args: cobra.ExactArgs(1), | ||
ValidArgsFunction: cobra.NoFileCompletions, | ||
}, | ||
} | ||
|
||
cmd.Run = cmd.run | ||
cmd.Flags().BoolVarP( | ||
&cmd.quiet, | ||
"quiet", "q", | ||
false, | ||
"suppress printing a result message", | ||
) | ||
|
||
return &cmd | ||
} | ||
|
||
func (c *releaseExistsCmd) run(cmd *cobra.Command, args []string) { | ||
ctx := cmd.Context() | ||
releaseName := args[0] | ||
psqlURL, err := postgresqlURL() | ||
exitOnErr(err) | ||
|
||
storageClt := mustNewCompatibleStorage(psqlURL) | ||
|
||
exists, err := storageClt.ReleaseExists(ctx, releaseName) | ||
exitOnErr(err) | ||
if !exists { | ||
if !c.quiet { | ||
stdout.Printf("release %s does not exist\n", term.Highlight(args[0])) | ||
} | ||
exitFunc(exitCodeNotExist) | ||
} | ||
|
||
if !c.quiet { | ||
stdout.Printf("release %s exists\n", term.Highlight(args[0])) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.