-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PDK-370) Adds a 'pdk module generate' redirect to 'pdk new module'.
- Loading branch information
Showing
8 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module PDK::CLI | ||
@module_cmd = @base_cmd.define_command do | ||
name 'module' | ||
usage _('module [options]') | ||
summary _('update your module metadata, etc.') | ||
description _('Performs tasks on the module project.') | ||
default_subcommand 'help' | ||
end | ||
|
||
@module_cmd.add_command Cri::Command.new_basic_help | ||
end | ||
|
||
require 'pdk/cli/module/generate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'tty-prompt' | ||
|
||
module PDK::CLI | ||
@module_generate_cmd = @module_cmd.define_command do | ||
name 'generate' | ||
usage _('generate [options] <module_name>') | ||
summary _('This command is now \'pdk new module\'.') | ||
|
||
PDK::CLI.template_url_option(self) | ||
|
||
flag nil, 'skip-interview', _('When specified, skips interactive querying of metadata.') | ||
|
||
run do |opts, args, _cmd| | ||
require 'pdk/generators/module' | ||
|
||
module_name = args[0] | ||
|
||
if module_name.nil? || module_name.empty? | ||
puts command.help | ||
exit 1 | ||
end | ||
|
||
PDK.logger.info(_('New modules are created using the ‘pdk new module’ command.')) | ||
prompt = TTY::Prompt.new(help_color: :cyan) | ||
redirect = PDK::CLI::Util::CommandRedirector.new(prompt) | ||
redirect.target_command('pdk new module') | ||
answer = redirect.run | ||
|
||
if answer | ||
opts[:name] = module_name | ||
opts[:target_dir] = module_name | ||
|
||
PDK.logger.info(_('Creating new module: %{modname}') % { modname: module_name }) | ||
PDK::Generate::Module.invoke(opts) | ||
else | ||
exit 1 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'tty-prompt' | ||
|
||
module PDK | ||
module CLI | ||
module Util | ||
class CommandRedirector < TTY::Prompt::AnswersCollector | ||
def pastel | ||
@pastel ||= Pastel.new | ||
end | ||
|
||
def target_command(cmd) | ||
@command = cmd | ||
end | ||
|
||
def run | ||
@prompt.puts _('Did you mean \'%{command}\'?') % { command: pastel.bold(@command) } | ||
@prompt.yes?('-->') | ||
rescue TTY::Prompt::Reader::InputInterrupt | ||
nil | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters