Skip to content

Commit

Permalink
Update lucky task (#1835)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jwoertink authored Sep 22, 2023
1 parent ecb57b1 commit 2c95e34
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 67 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/tasks/gen/task_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tasks/exec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
17 changes: 7 additions & 10 deletions tasks/gen/action/api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 7 additions & 10 deletions tasks/gen/action/browser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 7 additions & 10 deletions tasks/gen/component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 7 additions & 10 deletions tasks/gen/page.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
26 changes: 12 additions & 14 deletions tasks/gen/task.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,31 @@ 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"

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:
Expand All @@ -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
Expand Down
19 changes: 9 additions & 10 deletions tasks/routes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2c95e34

Please sign in to comment.