From cf0997b434efbbbaffc5c149aedd243571cfa1c4 Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 7 Feb 2023 16:12:31 +0100 Subject: [PATCH 1/6] fix: worker: add all task type flag Add all flag for the `lotus-worker tasks enable/disable` cmd --- cmd/lotus-worker/tasks.go | 51 ++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/cmd/lotus-worker/tasks.go b/cmd/lotus-worker/tasks.go index 7b446207318..af9a9af70be 100644 --- a/cmd/lotus-worker/tasks.go +++ b/cmd/lotus-worker/tasks.go @@ -45,32 +45,52 @@ var tasksEnableCmd = &cli.Command{ Name: "enable", Usage: "Enable a task type", ArgsUsage: "[" + settableStr + "]", - Action: taskAction(api.Worker.TaskEnable), + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Usage: "Enable all task types", + }, + }, + Action: taskAction(api.Worker.TaskEnable), } var tasksDisableCmd = &cli.Command{ Name: "disable", Usage: "Disable a task type", ArgsUsage: "[" + settableStr + "]", - Action: taskAction(api.Worker.TaskDisable), + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Usage: "Disable all task types", + }, + }, + Action: taskAction(api.Worker.TaskDisable), } func taskAction(tf func(a api.Worker, ctx context.Context, tt sealtasks.TaskType) error) func(cctx *cli.Context) error { return func(cctx *cli.Context) error { - if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 argument") + allFlag := cctx.Bool("all") + + if cctx.NArg() == 1 && allFlag { + return xerrors.Errorf("Cannot use --all flag with task type argument") + } + + if cctx.NArg() == 0 && !allFlag { + return xerrors.Errorf("Expected 1 argument or use --all flag") } var tt sealtasks.TaskType - for taskType := range allowSetting { - if taskType.Short() == cctx.Args().First() { - tt = taskType - break + if cctx.NArg() == 1 { + for taskType := range allowSetting { + if taskType.Short() == cctx.Args().First() { + tt = taskType + break + } } - } - if tt == "" { - return xerrors.Errorf("unknown task type '%s'", cctx.Args().First()) + if tt == "" { + return xerrors.Errorf("unknown task type '%s'", cctx.Args().First()) + } } api, closer, err := lcli.GetWorkerAPI(cctx) @@ -81,6 +101,15 @@ func taskAction(tf func(a api.Worker, ctx context.Context, tt sealtasks.TaskType ctx := lcli.ReqContext(cctx) + if allFlag { + for taskType := range allowSetting { + if err := tf(api, ctx, taskType); err != nil { + return err + } + } + return nil + } + return tf(api, ctx, tt) } } From 58c7c514c6bf70505241b6bdfbe8ac72547f1b7b Mon Sep 17 00:00:00 2001 From: Phi-rjan Date: Tue, 7 Feb 2023 16:47:16 +0100 Subject: [PATCH 2/6] Update cmd/lotus-worker/tasks.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Magiera --- cmd/lotus-worker/tasks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-worker/tasks.go b/cmd/lotus-worker/tasks.go index af9a9af70be..3c4c04629d0 100644 --- a/cmd/lotus-worker/tasks.go +++ b/cmd/lotus-worker/tasks.go @@ -44,7 +44,7 @@ var settableStr = func() string { var tasksEnableCmd = &cli.Command{ Name: "enable", Usage: "Enable a task type", - ArgsUsage: "[" + settableStr + "]", + ArgsUsage: "--all | [" + settableStr + "]", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "all", From 3fc1346d5b12e85f2366df0f9521a4db88573ae4 Mon Sep 17 00:00:00 2001 From: Phi-rjan Date: Tue, 7 Feb 2023 16:47:23 +0100 Subject: [PATCH 3/6] Update cmd/lotus-worker/tasks.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Magiera --- cmd/lotus-worker/tasks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-worker/tasks.go b/cmd/lotus-worker/tasks.go index 3c4c04629d0..aee0599890d 100644 --- a/cmd/lotus-worker/tasks.go +++ b/cmd/lotus-worker/tasks.go @@ -57,7 +57,7 @@ var tasksEnableCmd = &cli.Command{ var tasksDisableCmd = &cli.Command{ Name: "disable", Usage: "Disable a task type", - ArgsUsage: "[" + settableStr + "]", + ArgsUsage: "--all | [" + settableStr + "]", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "all", From 21d60201792cb3176741ef174a4a6878a26c0670 Mon Sep 17 00:00:00 2001 From: Phi-rjan Date: Tue, 7 Feb 2023 16:47:30 +0100 Subject: [PATCH 4/6] Update cmd/lotus-worker/tasks.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Łukasz Magiera --- cmd/lotus-worker/tasks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-worker/tasks.go b/cmd/lotus-worker/tasks.go index aee0599890d..73ca5eb0a01 100644 --- a/cmd/lotus-worker/tasks.go +++ b/cmd/lotus-worker/tasks.go @@ -75,7 +75,7 @@ func taskAction(tf func(a api.Worker, ctx context.Context, tt sealtasks.TaskType return xerrors.Errorf("Cannot use --all flag with task type argument") } - if cctx.NArg() == 0 && !allFlag { + if cctx.NArg() != 1 && !allFlag { return xerrors.Errorf("Expected 1 argument or use --all flag") } From d75f77b4c572fdcbd35654ea79cca0cd76d0607e Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 7 Feb 2023 17:12:42 +0100 Subject: [PATCH 5/6] make docsgen-cli make docsgen-cli --- documentation/en/cli-lotus-worker.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/en/cli-lotus-worker.md b/documentation/en/cli-lotus-worker.md index cfc4938bce6..84355c404f2 100644 --- a/documentation/en/cli-lotus-worker.md +++ b/documentation/en/cli-lotus-worker.md @@ -221,7 +221,7 @@ USAGE: lotus-worker tasks enable [command options] [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK] OPTIONS: - --help, -h show help (default: false) + --all Enable all task types (default: false) ``` @@ -234,6 +234,6 @@ USAGE: lotus-worker tasks disable [command options] [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK] OPTIONS: - --help, -h show help (default: false) + --all Disable all task types (default: false) ``` From 48233221541c11cdc53d3ae4c0747fbaf8c3100f Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 7 Feb 2023 17:44:54 +0100 Subject: [PATCH 6/6] retry make docsgen-cli retry make docsgen-cli with the new usage --- documentation/en/cli-lotus-worker.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/en/cli-lotus-worker.md b/documentation/en/cli-lotus-worker.md index 84355c404f2..426d64d6ca8 100644 --- a/documentation/en/cli-lotus-worker.md +++ b/documentation/en/cli-lotus-worker.md @@ -218,7 +218,7 @@ NAME: lotus-worker tasks enable - Enable a task type USAGE: - lotus-worker tasks enable [command options] [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK] + lotus-worker tasks enable [command options] --all | [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK] OPTIONS: --all Enable all task types (default: false) @@ -231,7 +231,7 @@ NAME: lotus-worker tasks disable - Disable a task type USAGE: - lotus-worker tasks disable [command options] [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK] + lotus-worker tasks disable [command options] --all | [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK] OPTIONS: --all Disable all task types (default: false)