func main()

in cmd/cli/main.go [864:1216]


func main() {
	app.Version(version)
	app.HelpFlag.Short('h')
	cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
	var err error

	if len(*clusterName) > 0 {
		var zkInfo string
		zkJSONBytes, err := config.ReadZKConfigFile()
		if err != nil {
			app.FatalIfError(err, "Fail to get zookeeper info")
		}
		zkInfo, err = config.GetZkInfoFromClusterName(*clusterName, zkJSONBytes)
		if err != nil {
			app.FatalIfError(err, "Fail to get zk info for this cluster")
		}
		zkInfoSlice := strings.Split(zkInfo, ",")
		// if user provides both cluster name and zk info, check whether the information matches
		if len(*zkServers) > 0 {
			for _, a := range *zkServers {
				if !util.Contains(zkInfoSlice, a) {
					app.Fatalf("zk info of cluster %s mismatch with provided zk server %s, please correct/remove the cluster name or zk server", *clusterName, a)
				}
			}
		}
		zkServers = &zkInfoSlice
	}
	var discovery leader.Discovery
	if len(*zkServers) > 0 {
		discovery, err = leader.NewZkServiceDiscovery(*zkServers, *zkRoot)
	} else {
		discovery, err = leader.NewStaticServiceDiscovery(*jobMgrURL, *resMgrURL, *hostMgrURL)
	}
	if err != nil {
		app.FatalIfError(err, "Fail to initialize service discovery")
	}

	var basicAuthConfigPtr *middleware.BasicAuthConfig
	if len(*basicAuthConfigFile) != 0 {
		var basicAuthConfig middleware.BasicAuthConfig
		if err := common_config.Parse(&basicAuthConfig, *basicAuthConfigFile); err != nil {
			app.FatalIfError(err, "Fail to load auth config file")
		}
		basicAuthConfigPtr = &basicAuthConfig
	}

	client, err := pc.New(discovery, *timeout, basicAuthConfigPtr, *jsonFormat)
	if err != nil {
		app.FatalIfError(err, "Fail to initialize client")
	}
	defer client.Cleanup()

	switch cmd {
	case jobCreate.FullCommand():
		err = client.JobCreateAction(*jobCreateID, *jobCreateResPoolPath,
			*jobCreateConfig, *jobCreateSecretPath, []byte(*jobCreateSecret))
	case jobDelete.FullCommand():
		err = client.JobDeleteAction(*jobDeleteName)
	case jobStop.FullCommand():
		err = client.JobStopAction(
			*jobStopName,
			*jobStopProgress,
			*jobStopOwner,
			*jobStopLabels,
			*jobStopForce,
			*jobStopLimit,
			*jobStopMaxLimit,
		)
	case jobGet.FullCommand():
		err = client.JobGetAction(*jobGetName)
	case jobRefresh.FullCommand():
		err = client.JobRefreshAction(*jobRefreshName)
	case jobStatus.FullCommand():
		err = client.JobStatusAction(*jobStatusName)
	case jobQuery.FullCommand():
		err = client.JobQueryAction(*jobQueryLabels, *jobQueryRespoolPath, *jobQueryKeywords, *jobQueryStates, *jobQueryOwner, *jobQueryName, *jobQueryTimeRange, *jobQueryLimit, *jobQueryMaxLimit, *jobQueryOffset, *jobQuerySortBy, *jobQuerySortOrder)
	case jobUpdate.FullCommand():
		err = client.JobUpdateAction(*jobUpdateID, *jobUpdateConfig,
			*jobUpdateSecretPath, []byte(*jobUpdateSecret))
	case jobRestart.FullCommand():
		err = client.JobRestartAction(*jobRestartName, *jobRestartResourceVersion, *jobRestartInstanceRanges, *jobRestartBatchSize)
	case jobStart.FullCommand():
		err = client.JobStartAction(*jobStartName, *jobStartResourceVersion, *jobStartInstanceRanges, *jobStartBatchSize)
	case jobStopV1Beta.FullCommand():
		err = client.JobStopV1BetaAction(*jobStopV1BetaName, *jobStopV1BetaResourceVersion, *jobStopV1BetaInstanceRanges, *jobStopV1BetaBatchSize)
	case jobGetCache.FullCommand():
		err = client.JobGetCacheAction(*jobGetCacheName)
	case jobGetActiveJobs.FullCommand():
		err = client.JobGetActiveJobsAction()
	case jobMgrInstanceAvailability.FullCommand():
		err = client.JobMgrGetInstanceAvailabilityInfoForJob(*jobMgrInstanceAvailabilityName, *jobMgrInstanceAvailabilityInstances)
	case taskGet.FullCommand():
		err = client.TaskGetAction(*taskGetJobName, *taskGetInstanceID)
	case taskGetCache.FullCommand():
		err = client.TaskGetCacheAction(*taskGetCacheName, *taskGetCacheInstanceID)
	case taskGetEvents.FullCommand():
		err = client.TaskGetEventsAction(*taskGetEventsJobName, *taskGetEventsInstanceID)
	case taskLogsGet.FullCommand():
		err = client.TaskLogsGetAction(*taskLogsGetFileName, *taskLogsGetJobName, *taskLogsGetInstanceID, *taskLogsGetTaskID)
	case taskList.FullCommand():
		err = client.TaskListAction(*taskListJobName, taskListInstanceRange)
	case taskQuery.FullCommand():
		err = client.TaskQueryAction(*taskQueryJobName, *taskQueryStates, *taskQueryTaskNames, *taskQueryTaskHosts, *taskQueryLimit, *taskQueryOffset, *taskQuerySortBy, *taskQuerySortOrder)
	case taskRefresh.FullCommand():
		err = client.TaskRefreshAction(*taskRefreshJobName, taskRefreshInstanceRange)
	case taskStart.FullCommand():
		err = client.TaskStartAction(*taskStartJobName, *taskStartInstanceRanges)
	case taskStop.FullCommand():
		err = client.TaskStopAction(*taskStopJobName,
			*taskStopInstanceRanges)
	case taskRestart.FullCommand():
		err = client.TaskRestartAction(*taskRestartJobName, *taskRestartInstanceRanges)
	case hostMaintenanceStart.FullCommand():
		err = client.HostMaintenanceStartAction(*hostMaintenanceStartHostname)
	case hostMaintenanceComplete.FullCommand():
		err = client.HostMaintenanceCompleteAction(*hostMaintenanceCompleteHostname)
	case hostQuery.FullCommand():
		err = client.HostQueryAction(*hostQueryStates)
	case hostcacheDump.FullCommand():
		err = client.HostCacheDump()
	case jobMgrThrottledPods.FullCommand():
		err = client.JobMgrGetThrottledPods()
	case jobMgrQueryJobCache.FullCommand():
		err = client.JobMgrQueryJobCache(*jobMgrQueryJobCacheLabels, *jobMgrQueryJobCacheName)
	case resMgrActiveTasks.FullCommand():
		err = client.ResMgrGetActiveTasks(*resMgrActiveTasksGetJobName, *resMgrActiveTasksGetRespoolID, *resMgrActiveTasksGetStates)
	case resMgrPendingTasks.FullCommand():
		err = client.ResMgrGetPendingTasks(*resMgrPendingTasksGetRespoolID,
			uint32(*resMgrPendingTasksGetLimit))
	case resMgrOrphanTasks.FullCommand():
		err = client.ResMgrGetOrphanTasks(*resMgrOrphanTasksRespoolID)
	case resPoolCreate.FullCommand():
		err = client.ResPoolCreateAction(*resPoolCreatePath, *resPoolCreateConfig)
	case respoolUpdate.FullCommand():
		err = client.ResPoolUpdateAction(*respoolUpdatePath, *respoolUpdateConfig, *respoolUpdateForce)
	case resPoolDump.FullCommand():
		err = client.ResPoolDumpAction(*resPoolDumpFormat)
	case resPoolDelete.FullCommand():
		err = client.ResPoolDeleteAction(*resPoolDeletePath)
	case volumeList.FullCommand():
		err = client.VolumeListAction(*volumeListJobName)
	case volumeDelete.FullCommand():
		err = client.VolumeDeleteAction(*volumeDeleteVolumeID)
	case updateCreate.FullCommand():
		err = client.UpdateCreateAction(
			*updateJobID,
			*updateCreateConfig,
			*updateBatchSize,
			*updateResPoolPath,
			*updateConfigVersion,
			*updateOverride,
			*updateMaxInstanceAttempts,
			*updateMaxFailureInstances,
			*updateRollbackOnFailure,
			*updateStartInPausedState,
			*updateCreateOpaqueData,
			*updateCreateInPlace,
		)
	case updateGet.FullCommand():
		err = client.UpdateGetAction(*updateGetID)
	case updateList.FullCommand():
		err = client.UpdateListAction(*updateListJobID)
	case updateCache.FullCommand():
		err = client.UpdateGetCacheAction(*updateCacheID)
	case updateAbort.FullCommand():
		err = client.UpdateAbortAction(*updateAbortID, *updateAbortOpaqueData)
	case updatePause.FullCommand():
		err = client.UpdatePauseAction(*updatePauseID, *updatePauseOpaqueData)
	case updateResume.FullCommand():
		err = client.UpdateResumeAction(*updateResumeID, *updateResumeOpaqueData)
	case offers.FullCommand():
		err = client.OffersGetAction()
	case getHosts.FullCommand():
		err = client.HostsGetAction(
			*getHostsCPU,
			*getHostsGPU,
			*getHostsMem,
			*getHostsDisk,
			*getHostsCmpLess,
			*getHostsHostnames,
			*getHostsRevocable,
		)
	case disableKillTasks.FullCommand():
		err = client.DisableKillTasksAction()
	case podGetEvents.FullCommand():
		err = client.PodGetEventsAction(*podGetEventsJobName, *podGetEventsInstanceID, *podGetEventsRunID, *podGetEventsLimit)
	case podGetCache.FullCommand():
		err = client.PodGetCacheAction(*podGetCachePodName)
	case podGetEventsV1Alpha.FullCommand():
		err = client.PodGetEventsV1AlphaAction(*podGetEventsV1AlphaPodName, *podGetEventsV1AlphaPodID)
	case podRefresh.FullCommand():
		err = client.PodRefreshAction(*podRefreshPodName)
	case podStart.FullCommand():
		err = client.PodStartAction(*podStartPodName)
	case watchEventHostSummary.FullCommand():
		err = client.WatchHostSummaryEvent(string(watchevent.HostSummary))
	case watchEventMesosUpdate.FullCommand():
		err = client.WatchEventStreamEvents(string(watchevent.EventStream))
	case statelessListJobs.FullCommand():
		err = client.StatelessListJobsAction()
	case statelessListPods.FullCommand():
		err = client.StatelessListPodsAction(*statelessListPodsJobID, statelessListPodsInstanceRange)
	case statelessGetCache.FullCommand():
		err = client.StatelessGetCacheAction(*statelessGetCacheName)
	case statelessRefresh.FullCommand():
		err = client.StatelessRefreshAction(*statelessRefreshName)
	case workflowPause.FullCommand():
		err = client.StatelessWorkflowPauseAction(
			*workflowPauseName,
			*workflowPauseEntityVersion,
			*workflowPauseOpaqueData,
		)
	case workflowResume.FullCommand():
		err = client.StatelessWorkflowResumeAction(
			*workflowResumeName,
			*workflowResumeEntityVersion,
			*workflowResumeOpaqueData,
		)
	case workflowAbort.FullCommand():
		err = client.StatelessWorkflowAbortAction(
			*workflowAbortName,
			*workflowAbortEntityVersion,
			*workflowAbortOpaqueData,
		)
	case statelessQuery.FullCommand():
		err = client.StatelessQueryAction(*statelessQueryLabels, *statelessQueryRespoolPath, *statelessQueryKeywords, *statelessQueryStates, *statelessQueryOwner, *statelessQueryName, *statelessQueryTimeRange, *statelessQueryLimit, *statelessQueryMaxLimit, *statelessQueryOffset, *statelessQuerySortBy, *statelessQuerySortOrder)
	case statelessReplace.FullCommand():
		err = client.StatelessReplaceJobAction(
			*statelessReplaceJobID,
			*statelessReplaceSpec,
			*statelessReplaceBatchSize,
			*statelessReplaceResPoolPath,
			*statelessReplaceEntityVersion,
			*statelessReplaceOverride,
			*statelessReplaceMaxInstanceRetries,
			*statelessReplaceMaxTolerableInstanceFailures,
			*statelessReplaceRollbackOnFailure,
			*statelessReplaceStartPaused,
			*statelessReplaceOpaqueData,
			*statelessReplaceInPlace,
			*statelessStartPods,
		)
	case statelessRollback.FullCommand():
		err = client.StatelessRollbackJobAction(
			*statelessRollbackJobID,
			*statelessRollbackBatchSize,
			*statelessRollbackEntityVersion,
			*statelessRollbackMaxInstanceRetries,
			*statelessRollbackMaxTolerableInstanceFailures,
			*statelessRollbackStartPaused,
			*statelessRollbackOpaqueData,
			*statelessRollbackInPlace,
			*statelessRollbackStartPods,
		)
	case statelessReplaceJobDiff.FullCommand():
		err = client.StatelessReplaceJobDiffAction(
			*statelessReplaceJobDiffJobID,
			*statelessReplaceJobDiffSpec,
			*statelessReplaceJobDiffEntityVersion,
			*statelessReplaceJobDiffResPoolPath,
		)
	case statelessStop.FullCommand():
		err = client.StatelessStopJobAction(*statelessStopJobID, *statelessStopEntityVersion)
	case statelessCreate.FullCommand():
		err = client.StatelessCreateAction(
			*statelessCreateID,
			*statelessCreateResPoolPath,
			*statelessCreateBatchSize,
			*statelessCreateSpec,
			*statelessCreateSecretPath,
			[]byte(*statelessCreateSecret),
			*statelessCreateOpaqueData,
			*statelessCreateStartInPausedState,
			*statelessCreateMaxInstanceRetries,
			*statelessCreateMaxTolerableInstanceFailures,
		)
	case statelessRestartJob.FullCommand():
		err = client.StatelessRestartJobAction(
			*statelessRestartName,
			*statelessRestartBatchSize,
			*statelessRestartVersion,
			*statelessRestartInstanceRanges,
			*statelessRestartOpaqueData,
			*statelessRestartInPlace,
		)
	case statelessListUpdates.FullCommand():
		err = client.StatelessListUpdatesAction(
			*statelessListUpdatesName,
			*statelessListUpdatesLimit,
		)
	case workflowEvents.FullCommand():
		err = client.StatelessWorkflowEventsAction(
			*workflowEventsJob,
			*workflowEventsInstance)
	case podLogsGet.FullCommand():
		err = client.PodLogsGetAction(*podLogsGetFileName, *podLogsGetPodName, *podLogsGetPodID)
	case podRestart.FullCommand():
		err = client.PodRestartAction(*podRestartName)
	case podStop.FullCommand():
		err = client.PodStopAction(*podStopPodName)
	case podGet.FullCommand():
		err = client.PodGetAction(*podGetPodName, *podGetStatusOnly, *podGetLimit)
	case podDeleteEvents.FullCommand():
		err = client.PodDeleteEvents(*podDeleteEventsPodName, *podDeleteEventsPodID)
	case statelessGet.FullCommand():
		err = client.StatelessGetAction(*statelessGetJobID, *statelessGetVersion, *statelessGetSummaryOnly)
	case podQueryPods.FullCommand():
		err = client.StatelessQueryPodsAction(
			*podQueryPodsJobID,
			*podQueryPodsStates,
			*podQueryPodsPodNames,
			*podQueryPodsHosts,
			*podQueryPodsLimit,
			*podQueryPodsOffset,
			*podQueryPodsSortBy,
			*podQueryPodsSortOrder,
		)
	case statelessStart.FullCommand():
		err = client.StatelessStartJobAction(*statelessStartJobID, *statelessStartEntityVersion)
	case statelessDelete.FullCommand():
		err = client.StatelessDeleteAction(
			*statelessDeleteJobID,
			*statelessDeleteEntityVersion,
			*statelessDeleteForce,
		)
	case watchJob.FullCommand():
		err = client.WatchJob(*watchJobIDList, *watchJobLabels)
	case watchPod.FullCommand():
		err = client.WatchPod(*watchPodJobID, *watchPodPodNames, *watchPodLabels)
	case watchCancel.FullCommand():
		err = client.CancelWatch(*watchCancelWatchID)
	case lock.FullCommand():
		err = client.LockComponents(*lockComponents)
	case unlock.FullCommand():
		err = client.UnlockComponents(*unlockComponents)
	case hostpoolList.FullCommand():
		err = client.HostPoolList()
	case hostpoolListHosts.FullCommand():
		err = client.HostPoolListHosts(*hostpoolListHostsName)
	case hostpoolCreate.FullCommand():
		err = client.HostPoolCreate(*hostpoolCreateName)
	case hostpoolDelete.FullCommand():
		err = client.HostPoolDelete(*hostpoolDeleteName)
	case hostpoolChangePool.FullCommand():
		err = client.HostPoolChangePool(
			*hostpoolChangePoolHost,
			*hostpoolChangePoolSource,
			*hostpoolChangePoolDest)
	default:
		app.Fatalf("Unknown command %s", cmd)
	}
	app.FatalIfError(err, "")
}