Skip to content

Commit

Permalink
feat: Add -task to alloc logs command (#10026)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-karan committed Feb 16, 2021
1 parent 49e5699 commit f159903
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions command/alloc_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Logs Specific Options:
-verbose
Show full information.
-task <task-name>
Sets the task to view the logs.
-job <job-id>
Use a random allocation from the specified job ID.
Expand Down Expand Up @@ -76,6 +79,7 @@ func (c *AllocLogsCommand) AutocompleteFlags() complete.Flags {
complete.Flags{
"-stderr": complete.PredictNothing,
"-verbose": complete.PredictNothing,
"-task": complete.PredictAnything,
"-job": complete.PredictAnything,
"-f": complete.PredictNothing,
"-tail": complete.PredictAnything,
Expand Down Expand Up @@ -104,6 +108,7 @@ func (l *AllocLogsCommand) Name() string { return "alloc logs" }
func (l *AllocLogsCommand) Run(args []string) int {
var verbose, job, tail, stderr, follow bool
var numLines, numBytes int64
var task string

flags := l.Meta.FlagSet(l.Name(), FlagSetClient)
flags.Usage = func() { l.Ui.Output(l.Help()) }
Expand All @@ -114,6 +119,7 @@ func (l *AllocLogsCommand) Run(args []string) int {
flags.BoolVar(&stderr, "stderr", false, "")
flags.Int64Var(&numLines, "n", -1, "")
flags.Int64Var(&numBytes, "c", -1, "")
flags.StringVar(&task, "task", "", "")

if err := flags.Parse(args); err != nil {
return 1
Expand Down Expand Up @@ -186,22 +192,25 @@ func (l *AllocLogsCommand) Run(args []string) int {
return 1
}

var task string
if len(args) >= 2 {
task = args[1]
if task == "" {
l.Ui.Error("Task name required")
return 1
}

// If -task isn't provided fallback to reading the task name
// from args.
if task != "" {
err = validateTaskExistsInAllocation(task, alloc)
} else {
task, err = lookupAllocTask(alloc)

if err != nil {
l.Ui.Error(err.Error())
return 1
if len(args) >= 2 {
task = args[1]
if task == "" {
l.Ui.Error("Task name required")
return 1
}
} else {
task, err = lookupAllocTask(alloc)
}
}
if err != nil {
l.Ui.Error(fmt.Sprintf("Failed to validate task: %s", err))
return 1
}

logType := "stdout"
if stderr {
Expand Down

0 comments on commit f159903

Please sign in to comment.