-
Notifications
You must be signed in to change notification settings - Fork 85
/
describe.go
71 lines (61 loc) · 1.97 KB
/
describe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package job
import (
"fmt"
"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/output"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/i18n"
)
var (
describeLong = templates.LongDesc(i18n.T(`
Full description of a job, in yaml format.
Use 'bacalhau job list' to get a list of jobs.
`))
describeExample = templates.Examples(i18n.T(`
# Describe a job with the full ID
bacalhau job describe j-e3f8c209-d683-4a41-b840-f09b88d087b9
# Describe a job with the a shortened ID
bacalhau job describe j-47805f5c
# Describe a job with json output
bacalhau job describe --output json --pretty j-b6ad164a
`))
)
// DescribeOptions is a struct to support job command
type DescribeOptions struct {
OutputOpts output.NonTabularOutputOptions
}
// NewDescribeOptions returns initialized Options
func NewDescribeOptions() *DescribeOptions {
return &DescribeOptions{
OutputOpts: output.NonTabularOutputOptions{Format: output.YAMLFormat},
}
}
func NewDescribeCmd() *cobra.Command {
o := NewDescribeOptions()
jobCmd := &cobra.Command{
Use: "describe [id]",
Short: "Get the info of a job by id.",
Long: describeLong,
Example: describeExample,
Args: cobra.ExactArgs(1),
Run: o.run,
}
jobCmd.Flags().AddFlagSet(cliflags.OutputNonTabularFormatFlags(&o.OutputOpts))
return jobCmd
}
func (o *DescribeOptions) run(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
jobID := args[0]
response, err := util.GetAPIClientV2(ctx).Jobs().Get(&apimodels.GetJobRequest{
JobID: jobID,
})
if err != nil {
util.Fatal(cmd, fmt.Errorf("could not get job %s: %w", jobID, err), 1)
}
if err = output.OutputOneNonTabular(cmd, o.OutputOpts, response.Job); err != nil {
util.Fatal(cmd, fmt.Errorf("failed to write job %s: %w", jobID, err), 1)
}
}