Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AddCmd = &cobra.Command{ Use: "add", Short: "Add job based on config", Long: `Add a job to server based on config. For example: mim jobs add -file <configfile.json> or mim jobs add -f <configfile.json> Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { format := utils.ResolveFormat(cmd) if format == "json" { pterm.DisableOutput() } server, token, err := login.ResolveCredentials() utils.HandleError(err) pterm.EnableDebugMessages() file, err := cmd.Flags().GetString("file") utils.HandleError(err) config, err := utils.ReadInput(file) utils.HandleError(err) pterm.Success.Println("Read config file") jobManager := api.NewJobManager(server, token) job, err := jobManager.AddJob(config) utils.HandleError(err) pterm.Success.Println("Added job to server") tfile, err := cmd.Flags().GetString("transform") if tfile != "" { var code []byte importer := transform.NewImporter(tfile) if filepath.Ext(tfile) == ".ts" { code, err = importer.ImportTs() } else { code, err = importer.ImportJs() } utils.HandleError(err) job, err = jobManager.AddTransform(job, importer.Encode(code)) if err != nil { pterm.Error.Println(fmt.Sprintf("Could not add Transform to job. Response from datahub was: %s", err)) pterm.Println() os.Exit(1) } pterm.Success.Println("Added transform to job") } pterm.Println() }, TraverseChildren: true, }
addCmd represents the add command
View Source
var DeleteCmd = &cobra.Command{ Use: "delete", Short: "Delete job with given job id", Long: `Delete a job with given id, For example: mim jobs delete --id <jobid> or mim jobs delete -i <jobid> Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { server, token, err := login.ResolveCredentials() utils.HandleError(err) idOrTitle, err := cmd.Flags().GetString("id") utils.HandleError(err) if len(args) > 0 { idOrTitle = args[0] } if idOrTitle == "" { pterm.Error.Println("You must provide an job id") os.Exit(1) } confirm, err := cmd.Flags().GetBool("confirm") utils.HandleError(err) pterm.EnableDebugMessages() jm := api.NewJobManager(server, token) id := jm.ResolveId(idOrTitle) pterm.DefaultSection.Println("Deleting job with id: " + id + " (" + idOrTitle + ") ") if confirm { pterm.Warning.Printf("Delete job with job id: " + id + " (" + idOrTitle + ") on " + server + ", please type (y)es or (n)o and then press enter:") if utils.AskForConfirmation() { err = jm.DeleteJob(id) utils.HandleError(err) pterm.Success.Println("Deleted job") pterm.Println() } else { pterm.Println("Aborted!") } } else { err = jm.DeleteJob(id) utils.HandleError(err) pterm.Success.Println("Deleted job") pterm.Println() } }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp } return api.GetJobsCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp }, TraverseChildren: true, }
deleteCmd represents the delete command
View Source
var GetCmd = &cobra.Command{ Use: "get", Short: "Get job description with given job id", Long: `For example: mim jobs get --id <jobid> or mim jobs get -i <jobid> Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { format := utils.ResolveFormat(cmd) if format != "term" { pterm.DisableOutput() } server, token, err := login.ResolveCredentials() utils.HandleError(err) pterm.EnableDebugMessages() idOrTitle, err := cmd.Flags().GetString("id") utils.HandleError(err) if len(args) > 0 && idOrTitle == "" { idOrTitle = args[0] } if idOrTitle == "" { pterm.Warning.Println("You must provide a job title or id") pterm.Println() os.Exit(1) } jm := api.NewJobManager(server, token) id := jm.ResolveId(idOrTitle) pterm.DefaultSection.Printf("Get description of job with id: " + id + " (" + idOrTitle + ") on " + server) job, err := jm.GetJob(id) utils.HandleError(err) renderJob(job, format) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp } return api.GetJobsCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp }, }
describeCmd represents the describe command
View Source
var HistoryCmd = &cobra.Command{ Use: "history", Short: "history for a job", Long: "history for a job", Example: "mim jobs history --id <jobid>", Run: func(cmd *cobra.Command, args []string) { format := utils.ResolveFormat(cmd) if format != "term" { pterm.DisableOutput() } server, token, err := login.ResolveCredentials() utils.HandleError(err) pterm.EnableDebugMessages() idOrTitle, err := cmd.Flags().GetString("id") utils.HandleError(err) if idOrTitle == "" && len(args) > 0 { idOrTitle = args[0] } if idOrTitle == "" { pterm.Warning.Println("You must provide a job title or id") pterm.Println() os.Exit(1) } jm := api.NewJobManager(server, token) id := jm.ResolveId(idOrTitle) pterm.DefaultSection.Printf("Get history of job with id: " + id + " (" + idOrTitle + ") on " + server) hist, err := jm.GetJobHistoryForId(id) utils.HandleError(err) renderHistory(hist, format) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp } return api.GetJobsCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp }, TraverseChildren: true, }
StatusCmd represents the staus command on a job
View Source
var ListCmd = &cobra.Command{ Use: "list", Aliases: []string{"ls"}, Short: "List a list of jobs", Long: `List a list of jobs. For example: mim jobs --list or mim jobs -l Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { format := utils.ResolveFormat(cmd) if format != "term" { pterm.DisableOutput() } server := web.GetServer() pterm.EnableDebugMessages() pterm.DefaultSection.Println("Listing server jobs on " + server) client, err := web.NewClient(server) utils.HandleError(err) jobs, err := client.GetRaw("/jobs") utils.HandleError(err) history, err := client.GetRaw("/jobs/_/history") utils.HandleError(err) filter, err := cmd.Flags().GetString("filter") if filter == "" && len(args) > 0 { filter = args[0] } filterMode, err := cmd.Flags().GetString("filterMode") utils.HandleError(err) output, err := listJobs(jobs, history) utils.HandleError(err) if filter != "" { output, err = filterJobs(output, filter, filterMode) utils.HandleError(err) } verbose, err := cmd.Flags().GetBool("verbose") if verbose { printOutput(output, "verbose") } else { printOutput(output, format) } pterm.Println() }, TraverseChildren: true, }
ListCmd represents the list command
View Source
var StatusCmd = &cobra.Command{ Use: "status", Short: "Status on jobs", Long: `Status on jobs, For example: mim jobs status --id <jobid> or mim jobs status `, Run: func(cmd *cobra.Command, args []string) { format := utils.ResolveFormat(cmd) if format != "term" { pterm.DisableOutput() } server, token, err := login.ResolveCredentials() utils.HandleError(err) pterm.EnableDebugMessages() idOrTitle, err := cmd.Flags().GetString("id") utils.HandleError(err) if idOrTitle == "" && len(args) > 0 { idOrTitle = args[0] } var id string jm := api.NewJobManager(server, token) if idOrTitle != "" { id = jm.ResolveId(idOrTitle) pterm.DefaultSection.Printf("Get status on job with job id: " + id + " (" + idOrTitle + ") on " + server) } else { pterm.DefaultSection.Printf("Get status on all running jobs on " + server) id = "" } jobs, err := jm.GetJobStatus(id) utils.HandleError(err) renderBody(jobs, format) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp } return api.GetJobsCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp }, TraverseChildren: true, }
StatusCmd represents the staus command on a job
Functions ¶
func CmdOperate ¶ added in v0.17.0
Types ¶
This section is empty.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.