mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
feat: Add -task to alloc logs command (#10026)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
@@ -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()) }
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user