Skip to content

Commit

Permalink
Add 'builds status' command.
Browse files Browse the repository at this point in the history
  • Loading branch information
lnsp committed Nov 14, 2023
1 parent b596004 commit c37b648
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ valar list
```

#### Show the logs of the latest deployment
```
valar logs [service]
```bash
valar logs [--follow] [--tail] [--skip n] [service]
```

#### Listing all deployments of a service
Expand Down Expand Up @@ -201,6 +201,10 @@ valar builds abort [prefix]
```bash
valar builds logs [--follow] [optional buildid]
```
#### Show build status
```bash
valar builds status [--exit] [buildid]
```
### Permissions
#### View permissions
```bash
Expand Down
38 changes: 38 additions & 0 deletions cmd/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ var inspectCmd = &cobra.Command{
}),
}

var statusCmd = &cobra.Command{
Use: "status [buildid]",
Short: "Show the status of the given build",
Args: cobra.ExactArgs(1),
Run: runAndHandle(func(cmd *cobra.Command, args []string) error {
cfg := &config.ServiceConfig{}
if err := cfg.ReadFromFile(functionConfiguration); err != nil {
return err
}
client, err := globalConfiguration.APIClient()
if err != nil {
return err
}
showBuildStatusAndExit(client, cfg, args[0])
return nil
}),
}

func listBuilds(client *api.Client, cfg *config.ServiceConfig, id string) error {
builds, err := client.ListBuilds(cfg.Project, cfg.Service, id)
if err != nil {
Expand All @@ -132,6 +150,16 @@ func listBuilds(client *api.Client, cfg *config.ServiceConfig, id string) error
return nil
}

func showBuildStatusAndExit(client *api.Client, cfg *config.ServiceConfig, id string) error {
build, err := client.InspectBuild(cfg.Project, cfg.Service, id)
if err != nil {
return err
}
fmt.Fprintln(os.Stdout, colorize(build.Status))
os.Exit(statusToExitCode(build.Status))
return nil
}

func inspectBuild(client *api.Client, cfg *config.ServiceConfig, id string) error {
build, err := client.InspectBuild(cfg.Project, cfg.Service, id)
if err != nil {
Expand Down Expand Up @@ -165,6 +193,15 @@ func deployBuild(client *api.Client, cfg *config.ServiceConfig, id string) error
return nil
}

func statusToExitCode(status string) int {
switch status {
case "done":
return 0
default:
return 1
}
}

func colorize(status string) string {
switch status {
case "scheduled", "waiting":
Expand All @@ -185,5 +222,6 @@ func initBuildsCmd() {
buildCmd.AddCommand(inspectCmd)
buildCmd.AddCommand(buildLogsCmd)
buildCmd.AddCommand(buildAbortCmd)
buildCmd.AddCommand(statusCmd)
rootCmd.AddCommand(buildCmd)
}

0 comments on commit c37b648

Please sign in to comment.