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

Refactor CLI options #707

Merged
merged 2 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/mina/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def run(*args)
# :nocov:

def sort_options(options)
not_applicable_to_mina = ['quiet', 'silent', 'verbose', 'dry-run']
options.reject! do |(switch, *)|
switch =~ /--#{Regexp.union(not_applicable_to_mina)}/
end
options_not_applicable_to_mina = /--#{Regexp.union(['quiet', 'silent', 'verbose', 'dry-run'])}/

super.push(version, verbose, simulate, debug_configuration_variables, no_report_time)
mina_options = options.reject { |(switch, *)| switch =~ options_not_applicable_to_mina }
mina_options += [version, verbose, simulate, debug_configuration_variables, no_report_time]

super(mina_options)
end

def top_level_tasks
Expand Down Expand Up @@ -56,7 +56,7 @@ def version
def verbose
[
'--verbose', '-v',
'Print more info',
'Print a command before its execution.',
lambda do |_value|
set(:verbose, true)
end
Expand All @@ -66,7 +66,7 @@ def verbose
def simulate
[
'--simulate', '-s',
'Do a simulate run without executing actions',
'Run a simulation. All commands will be printed but not executed.',
lambda do |_value|
set(:simulate, true)
end
Expand All @@ -76,7 +76,7 @@ def simulate
def debug_configuration_variables
[
'--debug-configuration-variables', '-d',
'Display the defined config variables before runnig the tasks.',
'Display configuration variables.',
lambda do |_value|
set(:debug_configuration_variables, true)
end
Expand All @@ -86,7 +86,7 @@ def debug_configuration_variables
def no_report_time
[
'--no-report-time', nil,
'Skip time reporting',
"Don't report execution time.",
lambda do |_value|
set(:skip_report_time, true)
end
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/mina/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@
end
end
end

describe 'Rake options' do
let(:options) { application.standard_rake_options }

it 'shows --verbose' do
expect(options.any? { |(switch, *)| switch == '--verbose' }).to eq(true)
end

it "doesn't show --dry-run" do
expect(options.any? { |(switch, *)| switch == '--dry-run' }).to eq(false)
end

it "doesn't show --quiet" do
expect(options.any? { |(switch, *)| switch == '--quiet' }).to eq(false)
end

it "doesn't show --silent" do
expect(options.any? { |(switch, *)| switch == '--silent' }).to eq(false)
end
end
end