Skip to content
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

Merged
merged 4 commits into from
Sep 8, 2017

Conversation

bmjen
Copy link
Contributor

@bmjen bmjen commented Sep 5, 2017

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.

@bmjen bmjen changed the title (PDK-370) Adds a 'pdk module generate' redirect to 'pdk new module'. {wip}(PDK-370) Adds a 'pdk module generate' redirect to 'pdk new module'. Sep 5, 2017
@bmjen
Copy link
Contributor Author

bmjen commented Sep 5, 2017

@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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.1%) to 92.76% when pulling 6035c27 on bmjen:pdk-370 into 32eee98 on puppetlabs:master.

@DavidS
Copy link
Contributor

DavidS commented Sep 6, 2017

👍

  • The module subcommand can be marked as hidden so it doesn't show up in pdk help.
  • Pressing enter, instead of yes on the Did you mean... question throws a exception:
/home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt/confirm_question.rb:125:in `block in conversion': undefined method `match' for true:TrueClass (NoMethodError)
Did you mean?  catch
	from /home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt/converter_registry.rb:55:in `call'
	from /home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt/converter_dsl.rb:18:in `convert'
	from /home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt/question.rb:203:in `convert_result'
	from /home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt/confirm_question.rb:78:in `render_question'
	from /home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt/question.rb:121:in `render'
	from /home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt/confirm_question.rb:65:in `call'
	from /home/david/gems/ruby/2.3.0/gems/tty-prompt-0.13.1/lib/tty/prompt.rb:314:in `yes?'
	from /home/david/git/pdk/lib/pdk/cli/util/command_redirector.rb:20:in `run'

def run
@prompt.print _('Did you mean \'')
@prompt.print pastel.bold(@command)
@prompt.puts _('\'?')
Copy link
Contributor

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)
Copy link
Contributor

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\'.')
Copy link
Contributor

@rickmonro rickmonro Sep 6, 2017

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

Copy link
Contributor Author

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

@bmjen bmjen force-pushed the pdk-370 branch 4 times, most recently from 86a5a85 to e83dd19 Compare September 6, 2017 21:45
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 92.81% when pulling e5eba34 on bmjen:pdk-370 into ff57c56 on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.1%) to 92.866% when pulling d26929d on bmjen:pdk-370 into ff57c56 on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 92.929% when pulling 86a5a85 on bmjen:pdk-370 into ff57c56 on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 92.925% when pulling e83dd19 on bmjen:pdk-370 into ff57c56 on puppetlabs:master.


PDK::CLI.template_url_option(self)

flag nil, 'skip-interview', _('When specified, skips interactive querying of metadata.')
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

@coveralls
Copy link

Coverage Status

Coverage decreased (-55.8%) to 38.211% when pulling 88ae2a5 on bmjen:pdk-370 into ff57c56 on puppetlabs:master.

end
end

# context 'with a no at the prompt' do
Copy link
Contributor Author

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.

Copy link
Contributor

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)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.839% when pulling faee13b on bmjen:pdk-370 into ff57c56 on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 93.898% when pulling cb83722 on bmjen:pdk-370 into ff57c56 on puppetlabs:master.

PDK::CLI.template_url_option(self)
PDK::CLI.skip_interview(self)

flag nil, 'skip-interview', _('When specified, skips interactive querying of metadata.')
Copy link
Contributor

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)

Copy link
Contributor Author

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. :(

@DavidS
Copy link
Contributor

DavidS commented Sep 8, 2017

👍

@DavidS DavidS added the feature label Sep 8, 2017
@bmjen bmjen changed the title {wip}(PDK-370) Adds a 'pdk module generate' redirect to 'pdk new module'. (PDK-370) Adds a 'pdk module generate' redirect to 'pdk new module'. Sep 8, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 93.993% when pulling 4473df7 on bmjen:pdk-370 into 8e5bbe5 on puppetlabs:master.

Copy link
Contributor

@scotje scotje left a 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)
Copy link
Contributor

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
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 93.993% when pulling 375c007 on bmjen:pdk-370 into 8e5bbe5 on puppetlabs:master.

@bmjen bmjen merged commit 14e3bdb into puppetlabs:master Sep 8, 2017
@bmjen bmjen deleted the pdk-370 branch September 8, 2017 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants