Skip to content

Commit

Permalink
(PDK-1333) Add command_spec rake task
Browse files Browse the repository at this point in the history
Introspects the populated Cri data structure to generate a JSON
specification of the PDK command structure for use in generating the
PowerShell cmdlets.
  • Loading branch information
rodjek committed Jul 2, 2019
1 parent ddd5b09 commit c990891
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rakelib/command_spec.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
task :command_spec do
require 'pdk/cli'
require 'json'

base_command = PDK::CLI.instance_variable_get('@base_cmd')
result = describe_command(base_command)
puts JSON.pretty_generate(result)
end

def describe_command(cri_command)
{
'name' => cri_command.name,
'aliases' => cri_command.aliases.to_a,
'description' => cri_command.description,
'hidden' => cri_command.hidden,
'summary' => cri_command.summary,
'usage' => cri_command.summary,
'options' => cri_command.option_definitions.map { |r| describe_option(r) },
'subcommands' => cri_command.subcommands.map { |r| describe_command(r) },
}
end

def describe_option(cri_option)
cri_option.reject { |k, _| k == :block }
end

0 comments on commit c990891

Please sign in to comment.