-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from Sage/versioning_info
[yaml_normalizer] Added terminal methods for more informative CLI access
- Loading branch information
Showing
14 changed files
with
122 additions
and
4 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
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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ module Helpers | |
end | ||
|
||
require 'yaml_normalizer/helpers/normalize' | ||
require 'yaml_normalizer/helpers/param_parser' |
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,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'optparse' | ||
|
||
module YamlNormalizer | ||
module Helpers | ||
# Methods handling passing of additional params from CLI | ||
module ParamParser | ||
# Parse the params provided to the service | ||
# @param [Array] args - params passed to the service | ||
# @return nil | ||
def parse_params(*args) | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: #{program_name} [options] file1, file2..." | ||
opts.on('-v', '--version', 'Prints the yaml_normalizer version') { print_version } | ||
opts.on('-h', '--help', 'Prints this help') { print_help(opts) } | ||
end.parse(args) | ||
end | ||
|
||
# Print current version of the tool | ||
def print_version | ||
print("#{YamlNormalizer::VERSION}\n") | ||
exit_success | ||
end | ||
|
||
# Print current version of the tool | ||
# @param [Option] opts - options of opt_parser object | ||
# @return nil | ||
def print_help(opts) | ||
print(opts) | ||
exit_success | ||
end | ||
|
||
private | ||
|
||
def program_name | ||
$PROGRAM_NAME.split('/').last | ||
end | ||
|
||
def exit_success | ||
exit unless ENV['ENV'] == 'test' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
module YamlNormalizer | ||
# The current Yaml Normalizer version | ||
VERSION = '1.1.0' | ||
VERSION = '1.2.0' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_examples :args_receving_service do | ||
describe 'param triggered methods' do | ||
subject { described_class.new(*args) } | ||
|
||
context 'when presented with version param' do | ||
['-v', '--version'].each do |param| | ||
let(:args) { [param] } | ||
|
||
it 'prints the version of software' do | ||
expect do | ||
subject.call | ||
end.to output("#{YamlNormalizer::VERSION}\n").to_stdout | ||
end | ||
end | ||
end | ||
|
||
context 'when presented with help param' do | ||
['-h', '--help'].each do |param| | ||
let(:args) { [param] } | ||
it 'prints the help message' do | ||
expect do | ||
subject.call | ||
end.to output("Usage: rspec [options] file1, file2...\n"\ | ||
" -v, --version Prints the yaml_normalizer version\n"\ | ||
" -h, --help Prints this help\n").to_stdout | ||
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