github.com/chenbh/concourse/v6@v6.4.2/fly/commands/schedule_job.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/chenbh/concourse/v6/fly/commands/internal/flaghelpers"
     7  	"github.com/chenbh/concourse/v6/fly/rc"
     8  )
     9  
    10  type ScheduleJobCommand struct {
    11  	Job flaghelpers.JobFlag `short:"j" long:"job" required:"true" value-name:"PIPELINE/JOB" description:"Name of a job to schedule"`
    12  }
    13  
    14  func (command *ScheduleJobCommand) Execute(args []string) error {
    15  	target, err := rc.LoadTarget(Fly.Target, Fly.Verbose)
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	err = target.Validate()
    21  	if err != nil {
    22  		return err
    23  	}
    24  
    25  	found, err := target.Team().ScheduleJob(command.Job.PipelineName, command.Job.JobName)
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	if !found {
    31  		return fmt.Errorf("%s/%s not found\n", command.Job.PipelineName, command.Job.JobName)
    32  	}
    33  
    34  	fmt.Printf("scheduled '%s'\n", command.Job.JobName)
    35  
    36  	return nil
    37  }