Skip to content

Commit

Permalink
passthru method added to api/jobs.list
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Nov 2, 2022
1 parent c288d29 commit a1d646a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,31 @@ func (j *Jobs) RegisterOpts(job *Job, opts *RegisterOptions, q *WriteOptions) (*
return &resp, wm, nil
}

type JobListFields struct {
Meta bool
}
type JobListOptions struct {
Fields *JobListFields
}

// List is used to list all of the existing jobs.
func (j *Jobs) List(q *QueryOptions) ([]*JobListStub, *QueryMeta, error) {
return j.ListOptions(nil, q)
}

// List is used to list all of the existing jobs.
func (j *Jobs) ListOptions(opts *JobListOptions, q *QueryOptions) ([]*JobListStub, *QueryMeta, error) {
var resp []*JobListStub
qm, err := j.client.query("/v1/jobs", &resp, q)

destinationURL := "/v1/jobs"

if opts != nil && opts.Fields != nil {
qp := url.Values{}
qp.Add("Meta", fmt.Sprint(opts.Fields.Meta))
destinationURL = destinationURL + "?" + qp.Encode()
}

qm, err := j.client.query(destinationURL, &resp, q)
if err != nil {
return nil, qm, err
}
Expand Down
2 changes: 1 addition & 1 deletion command/job_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *JobStatusCommand) Run(args []string) int {

// Invoke list mode if no job ID.
if len(args) == 0 {
jobs, _, err := client.Jobs().List(nil)
jobs, _, err := client.Jobs().ListOptions(nil, nil)

if err != nil {
c.Ui.Error(fmt.Sprintf("Error querying jobs: %s", err))
Expand Down

0 comments on commit a1d646a

Please sign in to comment.