-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PDK-370) Adds a 'pdk module generate' redirect to 'pdk new module'. #286
Conversation
@puppetlabs/pdk and @rickmonro Please pull this and try out the new CLI subcommand for UX feedback. I'll be adding unit and acceptance tests. |
👍
|
def run | ||
@prompt.print _('Did you mean \'') | ||
@prompt.print pastel.bold(@command) | ||
@prompt.puts _('\'?') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translators will flag this as untranslatable.
It does work as @prompt.print _('Did you mean \'%{command}\'?') % { command: pastel.bold(@command) }
.
opts[:target_dir] = target_dir.nil? ? module_name : target_dir | ||
|
||
PDK.logger.info(_('Creating new module: %{modname}') % { modname: module_name }) | ||
PDK::Generate::Module.invoke(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If PDK::Generate::Module.invoke
is horrible enough to require a helper to be called, please fix the actual API, instead of layering on!
@module_generate_cmd = @module_cmd.define_command do | ||
name 'generate' | ||
usage _('generate [options] <module_name>') | ||
summary _('This command is now \'pdk new module\'.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even a line of (info) would be helpful to assist the user here, so perhaps:
pdk (INFO): New modules are created using the ‘pdk new module’ command.
Did you mean pdk new module? Y/n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the info line at line:23
86a5a85
to
e83dd19
Compare
lib/pdk/cli/module/generate.rb
Outdated
|
||
PDK::CLI.template_url_option(self) | ||
|
||
flag nil, 'skip-interview', _('When specified, skips interactive querying of metadata.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth abstracting this flag out into its own method like template-url
so that we only have 1 copy of the string if we want to change the wording in the future.
end | ||
|
||
PDK.logger.info(_('New modules are created using the ‘pdk new module’ command.')) | ||
prompt = TTY::Prompt.new(help_color: :cyan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a different colour to the help text in the rest of the prompts (probably a lot more readable than "bright black", not to mention a lot less painful to try to imagine). Should we adjust the help text in the interview to also use cyan for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodjek the interview also uses cyan as the help_color
. The TTY::Prompt is just set up and passed into the interview from the generator.
https://github.com/puppetlabs/pdk/blob/master/lib/pdk/generators/module.rb#L217
end | ||
end | ||
|
||
# context 'with a no at the prompt' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodjek need your help here. When I uncomment this context, rspec only runs the tests in this file and skips everything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bmjen fixed that up, you needed to catch the SystemExit exception raised by PDK::CLI.run (because the code calls exit 1
which makes rspec exit)
lib/pdk/cli/module/generate.rb
Outdated
PDK::CLI.template_url_option(self) | ||
PDK::CLI.skip_interview(self) | ||
|
||
flag nil, 'skip-interview', _('When specified, skips interactive querying of metadata.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should make use of PDK::CLI.skip_interview(self)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol. it does. Looks like I did an errant Ctrl-R in vim to readd this line. It's adding skip-interview twice. :(
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one nitpick naming comment but overall looks good!
lib/pdk/cli.rb
Outdated
@@ -36,6 +37,10 @@ def self.template_url_option(dsl) | |||
dsl.option nil, 'template-url', _('Specifies the URL to the template to use when creating new modules or classes.'), argument: :required, default: PDK::Generate::Module.default_template_url | |||
end | |||
|
|||
def self.skip_interview(dsl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: might call this skip_interview_option
(fixup) Remove extra skip-interview flag Adds accessor function for command redirect (PDK-370) Updates name of skip_interview helper
This new CLI option is meant to mirror the 'puppet module generate' command for experienced module developers used to the old method of generating a module skeleton. This CLI option redirects to 'pdk new module' after an initial prompt confirming the user's intent.