Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add -task to alloc logs command #10026

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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