// NewVersionOptions constructor func NewVersionOptions(c util.Settings, e *util.Environment) (*VersionOptions, error) { json, _ := c.Bool("json") beta, _ := c.Bool("beta") noUpdateCheck, _ := c.Bool("no-update-check") return &VersionOptions{ OutputJSON: json, BetaChannel: beta, CheckForUpdate: !noUpdateCheck, }, nil }
// NewDockerOptions constructor func NewDockerOptions(c util.Settings, e *util.Environment) (*DockerOptions, error) { dockerHost, _ := c.String("docker-host") dockerTLSVerify, _ := c.String("docker-tls-verify") dockerCertPath, _ := c.String("docker-cert-path") dockerDNS, _ := c.StringSlice("docker-dns") dockerLocal, _ := c.Bool("docker-local") speculativeOptions := &DockerOptions{ DockerHost: dockerHost, DockerTLSVerify: dockerTLSVerify, DockerCertPath: dockerCertPath, DockerDNS: dockerDNS, DockerLocal: dockerLocal, } // We're going to try out a few settings and set DockerHost if // one of them works, it they don't we'll get a nice error when // requireDockerEndpoint triggers later on guessAndUpdateDockerOptions(speculativeOptions, e) return speculativeOptions, nil }
// NewReporterOptions constructor func NewReporterOptions(c util.Settings, e *util.Environment, globalOpts *GlobalOptions) (*ReporterOptions, error) { shouldReport, _ := c.Bool("report") reporterHost, _ := c.String("wercker-host") reporterKey, _ := c.String("wercker-token") if shouldReport { if reporterKey == "" { return nil, errors.New("wercker-token is required") } if reporterHost == "" { return nil, errors.New("wercker-host is required") } } return &ReporterOptions{ GlobalOptions: globalOpts, ReporterHost: reporterHost, ReporterKey: reporterKey, ShouldReport: shouldReport, }, nil }
// NewKeenOptions constructor func NewKeenOptions(c util.Settings, e *util.Environment, globalOpts *GlobalOptions) (*KeenOptions, error) { keenMetrics, _ := c.Bool("keen-metrics") keenProjectWriteKey, _ := c.String("keen-project-write-key") keenProjectID, _ := c.String("keen-project-id") if keenMetrics { if keenProjectWriteKey == "" { return nil, errors.New("keen-project-write-key is required") } if keenProjectID == "" { return nil, errors.New("keen-project-id is required") } } return &KeenOptions{ GlobalOptions: globalOpts, KeenProjectID: keenProjectID, KeenProjectWriteKey: keenProjectWriteKey, ShouldKeenMetrics: keenMetrics, }, nil }
// NewPullOptions constructor func NewPullOptions(c util.Settings, e *util.Environment) (*PullOptions, error) { globalOpts, err := NewGlobalOptions(c, e) if err != nil { return nil, err } // dockerOpts, err := NewDockerOptions(c, e, globalOpts) // if err != nil { // return nil, err // } repository, _ := c.String("target") output, _ := c.String("output") outputDir, err := filepath.Abs(output) if err != nil { return nil, err } branch, _ := c.String("branch") status, _ := c.String("status") result, _ := c.String("result") load, _ := c.Bool("load") force, _ := c.Bool("force") return &PullOptions{ GlobalOptions: globalOpts, // DockerOptions: dockerOpts, Repository: repository, Branch: branch, Status: status, Result: result, Output: outputDir, Load: load, Force: force, }, nil }
// NewPipelineOptions big-ass constructor func NewPipelineOptions(c util.Settings, e *util.Environment) (*PipelineOptions, error) { globalOpts, err := NewGlobalOptions(c, e) if err != nil { return nil, err } // dockerOpts, err := NewDockerOptions(c, e, globalOpts) // if err != nil { // return nil, err // } awsOpts, err := NewAWSOptions(c, e, globalOpts) if err != nil { return nil, err } gitOpts, err := NewGitOptions(c, e, globalOpts) if err != nil { return nil, err } keenOpts, err := NewKeenOptions(c, e, globalOpts) if err != nil { return nil, err } reporterOpts, err := NewReporterOptions(c, e, globalOpts) if err != nil { return nil, err } buildID, _ := c.String("build-id") deployID, _ := c.String("deploy-id") pipelineID := "" if deployID != "" { pipelineID = deployID } else { pipelineID = buildID } deployTarget, _ := c.String("deploy-target") pipeline, _ := c.String("pipeline") applicationName, err := guessApplicationName(c, e) if err != nil { return nil, err } applicationID := guessApplicationID(c, e, applicationName) applicationOwnerName := guessApplicationOwnerName(c, e) applicationStartedByName, _ := c.String("application-started-by-name") if applicationStartedByName == "" { applicationStartedByName = applicationOwnerName } repository, _ := c.String("commit") shouldCommit := (repository != "") tag := guessTag(c, e) message := guessMessage(c, e) shouldStoreLocal, _ := c.Bool("store-local") shouldStoreS3, _ := c.Bool("store-s3") workingDir, _ := c.String("working-dir") workingDir, _ = filepath.Abs(workingDir) guestRoot, _ := c.String("guest-root") mntRoot, _ := c.String("mnt-root") reportRoot, _ := c.String("report-root") projectID := guessProjectID(c, e) projectPath := guessProjectPath(c, e) projectURL := guessProjectURL(c, e) if projectPath == workingDir { return nil, fmt.Errorf("Project path can't be the same as the working dir") } // These timeouts are given in minutes but we store them as milliseconds commandTimeoutFloat, _ := c.Float64("command-timeout") commandTimeout := int(commandTimeoutFloat * 1000 * 60) noResponseTimeoutFloat, _ := c.Float64("no-response-timeout") noResponseTimeout := int(noResponseTimeoutFloat * 1000 * 60) shouldArtifacts, _ := c.Bool("artifacts") // TODO(termie): switch negative flag shouldRemove, _ := c.Bool("no-remove") shouldRemove = !shouldRemove sourceDir, _ := c.String("source-dir") attachOnError, _ := c.Bool("attach-on-error") directMount, _ := c.Bool("direct-mount") enableDevSteps, _ := c.Bool("enable-dev-steps") publishPorts, _ := c.StringSlice("publish") enableVolumes, _ := c.Bool("enable-volumes") werckerYml, _ := c.String("wercker-yml") return &PipelineOptions{ GlobalOptions: globalOpts, AWSOptions: awsOpts, // DockerOptions: dockerOpts, GitOptions: gitOpts, KeenOptions: keenOpts, ReporterOptions: reporterOpts, HostEnv: e, BuildID: buildID, DeployID: deployID, PipelineID: pipelineID, DeployTarget: deployTarget, Pipeline: pipeline, ApplicationID: applicationID, ApplicationName: applicationName, ApplicationOwnerName: applicationOwnerName, ApplicationStartedByName: applicationStartedByName, Message: message, Tag: tag, Repository: repository, ShouldCommit: shouldCommit, ShouldStoreLocal: shouldStoreLocal, ShouldStoreS3: shouldStoreS3, WorkingDir: workingDir, GuestRoot: guestRoot, MntRoot: mntRoot, ReportRoot: reportRoot, ProjectID: projectID, ProjectURL: projectURL, ProjectPath: projectPath, CommandTimeout: commandTimeout, NoResponseTimeout: noResponseTimeout, ShouldArtifacts: shouldArtifacts, ShouldRemove: shouldRemove, SourceDir: sourceDir, AttachOnError: attachOnError, DirectMount: directMount, EnableDevSteps: enableDevSteps, PublishPorts: publishPorts, EnableVolumes: enableVolumes, WerckerYml: werckerYml, }, nil }