@@ -6,29 +6,35 @@ abstract class LuckyTask::Task
66 property output : IO = STDOUT
77
88 {% if ! @type .abstract? % }
9- LuckyTask ::Runner .register_task(self .new )
9+ LuckyTask ::Runner .register_task(self )
1010 {% end % }
1111
12- @[Deprecated (" Use `task_name` instead." )]
13- def name : String
14- task_name
12+ # The name of your task as derived by the class name
13+ # Use the `task_name` macro to define a custom task name
14+ def self.task_name : String
15+ " {{@type.name.gsub(/::/, " ." ).underscore}}"
1516 end
1617
17- def task_name : String
18- " {{@type.name.gsub(/::/, " ." ).underscore}}"
18+ # By default, task summaries are optional.
19+ # Use the `summary` macro to define a custom summary
20+ def self.task_summary : String
21+ " "
1922 end
2023
21- def help_message : String
22- <<-TEXT
23- #{ summary }
24+ # The help text to be displayed when a help flag
25+ # is passed in (e.g. -h, --help)
26+ # Use the `help_message`
27+ def self.task_help_message : String
28+ <<-TEXT .strip
29+ #{ task_summary }
2430
2531 Run this task with 'lucky #{ task_name } '
2632 TEXT
2733 end
2834
2935 def print_help_or_call (args : Array (String ))
3036 if wants_help_message?(args)
31- output.puts help_message
37+ output.puts self .class.task_help_message
3238 else
3339 \{% for opt in @type .constant(:PARSER_OPTS ) % }
3440 set_opt_for_\{{ opt.id }}(args)
@@ -43,24 +49,16 @@ abstract class LuckyTask::Task
4349 end
4450 end
4551
52+ # The general description of what this task does
53+ #
54+ # This is used in the help_text when a help flag is passed
55+ # to the task through the CLI
4656 macro summary (summary_text )
47- def summary : String
57+ def self.task_summary : String
4858 {{summary_text}}
4959 end
5060 end
5161
52- # DEPRECATED: Use `task_name` instead
53- macro name (name_text )
54- @[Deprecated (" Use `task_name` instead." )]
55- def name
56- task_name
57- end
58-
59- def task_name : String
60- {{name_text}}
61- end
62- end
63-
6462 # Renames the task name for CLI use
6563 #
6664 # By default the task name is derived from the full module and class name.
@@ -75,12 +73,28 @@ abstract class LuckyTask::Task
7573 # # other methods, etc.
7674 # end
7775 # ```
78- macro task_name (name_text )
79- def task_name : String
76+ macro name (name_text )
77+ def self. task_name : String
8078 {{name_text}}
8179 end
8280 end
8381
82+ # Customize your help message with the provided `help_text`
83+ #
84+ # ```
85+ # class KeyGen < LuckyTask::Task
86+ # summary "Generate a new key"
87+ # help_message "Call lucky key_gen to generate a new key"
88+ #
89+ # # other methods, etc.
90+ # end
91+ # ```
92+ macro help_message (help_text )
93+ def self.task_help_message : String
94+ {{help_text}}
95+ end
96+ end
97+
8498 # Creates a method of `arg_name` that returns the value passed in from the CLI.
8599 # The CLI arg position is based on the order in which `positional_arg` is specified
86100 # with the first call being position 0, and so on.
@@ -279,5 +293,4 @@ abstract class LuckyTask::Task
279293 end
280294
281295 abstract def call
282- abstract def summary : String
283296end
0 commit comments