From 2c95e349ce3fa857b7bfd3ae612f943873b9af08 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Fri, 22 Sep 2023 11:00:24 -0700 Subject: [PATCH] Update lucky task (#1835) * Using the latest LuckyTask version * Updating all of the built-in tasks to conform to new LuckyTask. Also cleans up the UI for the gen.task task --- shard.yml | 2 +- spec/tasks/gen/task_spec.cr | 2 +- tasks/exec.cr | 2 +- tasks/gen/action/api.cr | 17 +++++++---------- tasks/gen/action/browser.cr | 17 +++++++---------- tasks/gen/component.cr | 17 +++++++---------- tasks/gen/page.cr | 17 +++++++---------- tasks/gen/task.cr | 26 ++++++++++++-------------- tasks/routes.cr | 19 +++++++++---------- 9 files changed, 52 insertions(+), 67 deletions(-) diff --git a/shard.yml b/shard.yml index b40cb53ed..6f46de230 100644 --- a/shard.yml +++ b/shard.yml @@ -29,7 +29,7 @@ targets: dependencies: lucky_task: github: luckyframework/lucky_task - version: ~> 0.2.0 + version: ~> 0.3.0 habitat: github: luckyframework/habitat version: ~> 0.4.7 diff --git a/spec/tasks/gen/task_spec.cr b/spec/tasks/gen/task_spec.cr index ad9db03fa..d80c43d1a 100644 --- a/spec/tasks/gen/task_spec.cr +++ b/spec/tasks/gen/task_spec.cr @@ -14,7 +14,7 @@ describe Gen::Task do it "generates a task" do with_cleanup do output = run_with_args ["search.reindex"] - output.to_s.should contain("Generated ./tasks/search/reindex.cr") + output.to_s.should contain("./tasks/search/reindex.cr") should_create_files_with_contents output, "./tasks/search/reindex.cr": "Search::Reindex" end diff --git a/tasks/exec.cr b/tasks/exec.cr index 1facdb778..60db59a3f 100644 --- a/tasks/exec.cr +++ b/tasks/exec.cr @@ -3,7 +3,7 @@ require "habitat" require "lucky_task" class Lucky::Exec < LuckyTask::Task - task_name "exec" + name "exec" summary "Execute code. Use this in place of a console/REPL" arg :editor, "Which editor to use", shortcut: "-e", optional: true arg :back, "Load code from this many sessions back. Default is 1.", diff --git a/tasks/gen/action/api.cr b/tasks/gen/action/api.cr index de35b7faf..2a1d67b52 100644 --- a/tasks/gen/action/api.cr +++ b/tasks/gen/action/api.cr @@ -5,19 +5,16 @@ class Gen::Action::Api < LuckyTask::Task include Gen::ActionGenerator summary "Generate a new api action" + help_message <<-TEXT + #{task_summary} - positional_arg :action_name, "The name of the action" - switch :with_page, "This flag is used with gen.action.browser Only" - - def help_message - <<-TEXT - #{summary} + Example: - Example: + lucky gen.action.api Api::Users::Index + TEXT - lucky gen.action.api Api::Users::Index - TEXT - end + positional_arg :action_name, "The name of the action" + switch :with_page, "This flag is used with gen.action.browser Only" def call render_action_template(output, inherit_from: "ApiAction") diff --git a/tasks/gen/action/browser.cr b/tasks/gen/action/browser.cr index daa2a3073..991cdbf4b 100644 --- a/tasks/gen/action/browser.cr +++ b/tasks/gen/action/browser.cr @@ -7,19 +7,16 @@ class Gen::Action::Browser < LuckyTask::Task include Gen::ActionGenerator summary "Generate a new browser action" + help_message <<-TEXT + #{task_summary} - positional_arg :action_name, "The name of the action" - switch :with_page, "Generate a Page matching this Action" - - def help_message - <<-TEXT - #{summary} + Example: - Example: + lucky gen.action.browser Users::Index + TEXT - lucky gen.action.browser Users::Index - TEXT - end + positional_arg :action_name, "The name of the action" + switch :with_page, "Generate a Page matching this Action" def call render_action_template(output, inherit_from: "BrowserAction") diff --git a/tasks/gen/component.cr b/tasks/gen/component.cr index b8b00cb93..1587117c8 100644 --- a/tasks/gen/component.cr +++ b/tasks/gen/component.cr @@ -15,6 +15,13 @@ end class Gen::Component < LuckyTask::Task summary "Generate a new HTML component" + help_message <<-TEXT + #{task_summary} + + Example: + + lucky gen.component SettingsMenu + TEXT def call(io : IO = STDOUT) if error @@ -25,16 +32,6 @@ class Gen::Component < LuckyTask::Task end end - def help_message - <<-TEXT - #{summary} - - Example: - - lucky gen.component SettingsMenu - TEXT - end - private def error missing_name_error || invalid_format_error end diff --git a/tasks/gen/page.cr b/tasks/gen/page.cr index b064480be..99f1d3341 100644 --- a/tasks/gen/page.cr +++ b/tasks/gen/page.cr @@ -16,6 +16,13 @@ end class Gen::Page < LuckyTask::Task summary "Generate a new HTML page" + help_message <<-TEXT + #{task_summary} + + Example: + + lucky gen.page Users::IndexPage + TEXT positional_arg :page_class, "The name of the page" @@ -28,16 +35,6 @@ class Gen::Page < LuckyTask::Task end end - def help_message - <<-TEXT - #{summary} - - Example: - - lucky gen.page Users::IndexPage - TEXT - end - private def error missing_name_error || invalid_page_format_error end diff --git a/tasks/gen/task.cr b/tasks/gen/task.cr index d81d8b526..c729cbed7 100644 --- a/tasks/gen/task.cr +++ b/tasks/gen/task.cr @@ -16,6 +16,14 @@ end class Gen::Task < LuckyTask::Task summary "Generate a lucky command line task" + help_message <<-TEXT + #{task_summary} + + Example: + lucky gen.task email.monthly_update + + See Also: https://luckyframework.org/guides/command-line-tasks/custom-tasks + TEXT arg :task_summary, "The -h help text for the task", optional: true positional_arg :task_name, "The name of the task to generate" @@ -23,14 +31,16 @@ class Gen::Task < LuckyTask::Task def call errors = error_messages if !errors.empty? - output.puts errors + errors.each do |err| + output.puts err.colorize.red + end else Lucky::TaskTemplate .new(task_filename, rendered_task_name, rendered_summary) .render(output_path.to_s) output.puts <<-TEXT - Generated #{output_path.join task_filename} + Generated #{output_path.join(task_filename).colorize.green} Run it with: @@ -48,18 +58,6 @@ class Gen::Task < LuckyTask::Task messages end - def help_message - <<-TEXT - - #{summary} - - Example: - lucky gen.task email.monthly_update - - See Also: https://luckyframework.org/guides/command-line-tasks/custom-tasks - TEXT - end - private def relative_path Path[task_name.split('.')[0...-1]] end diff --git a/tasks/routes.cr b/tasks/routes.cr index 628f189af..8e14bfd2d 100644 --- a/tasks/routes.cr +++ b/tasks/routes.cr @@ -4,21 +4,20 @@ require "shell-table" class Routes < LuckyTask::Task summary "Show all the routes for the app" + help_message <<-TEXT + #{task_summary} - switch :with_params, "Include action params with each route", shortcut: "-p" + Optionally, you can pass the --with-params flag (-p) to print out + the available params for each Action. - def help_message - <<-TEXT - #{summary} + example: lucky routes --with-params - Optionally, you can pass the --with-params flag (-p) to print out - the available params for each Action. + Routing documentation: - example: lucky routes --with-params + https://luckyframework.org/guides/http-and-routing/routing-and-params + TEXT - #{print_banner_message} - TEXT - end + switch :with_params, "Include action params with each route", shortcut: "-p" def call routes = [] of Array(String)