README.md in easy_opt_parser-0.0.1 vs README.md in easy_opt_parser-0.0.2

- old
+ new

@@ -1,10 +1,10 @@ -# EasyOptParser +# EasyOptParser (EOP) -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/easy_opt_parser`. To experiment with that code, run `bin/console` for an interactive prompt. +Easy Opt Parser is a small simplification of the class `OptParser`. -TODO: Delete this and the text above, and describe your gem +The objective of this gem is to make easier the way to create command line options for your command. This gem is using the basic of OptParser and can be expanded over time. ## Installation Add this line to your application's Gemfile: @@ -12,28 +12,165 @@ gem 'easy_opt_parser' ``` And then execute: - $ bundle + $ bundle install Or install it yourself as: $ gem install easy_opt_parser ## Usage -TODO: Write usage instructions here +Let's see how it works! +Create a `dir` where you want and inside create two files: + +`Gemfile` and `test.rb` + +Inside `Gemfile` + +```ruby +gem 'easy_opt_parser' +``` + +Then run + +```bash +bundle install +``` + +Inside `test.rb` write this code + +```ruby +require 'easy_opt_parser' +require 'easy_opt_parser/domain/optional_argument' +require 'easy_opt_parser/domain/required_argument' +require 'easy_opt_parser/domain/flag_argument' + +def arguments + [ + EOP::RequiredArgument.new(name: 'required', + short_option: '-r', + long_option: '--required', + description: 'This is a required argument'), + + EOP::OptionalArgument.new(name: 'optional', + short_option: '-o', + long_option: '--optional', + description: 'This is an optional argument'), + + EOP::FlagArgument.new(name: 'flag', + short_option: '-f', + long_option: '--flag', + description: 'This is a flag argument'), + ] +end + + +parser = EasyOptionParser.new('Test Arguments', arguments) + +puts parser.options +``` + +This code shows that the only thing we need to do is to create an `Array` of `RequiredArgumen`, `OptionalArgumen` or `FlagArgument`. + +`RequiredArgument`: In the help description will be added a `*` symbol to determinate that is required. Also the gem will check all required arguments to be present and with values, if not an exception will be raised. + +`OptionalArgument`: Not necessary to be in command line, default value will be `nil`. If the argument is present but without value and error will be raised. + +`FlagArgument`: Not necessary to be in command line, default value will be `false`. If the flag appears the value will be `true` + +An extra argument is automatically added `-h` and `--help` to display the different arguments. + +## Examples + +Using the `Usage` example lets see the output the diffent outputs. + +`help` argument + +```bash +bundle exec ruby test.rb -h +``` + +Output + +```bash +Test Arguments + -r, --required required This is a required argument * + -o, --optional optional This is an optional argument + -f, --flag This is a flag argument + -h, --help Displays Help +``` + +`required` argument + +```bash +bundle exec ruby test.rb +``` + +Output + +```bash + Missing Argument [required] (RuntimeError) +``` + +`required` is obviously a required argument, so the system will raise an error in this case + +```bash +bundle exec ruby test.rb -r myValue +``` + +Output + +```bash + {:required=>"myValue", :optional=>nil, :flag=>false} +``` + +`optional` argument + +```bash +bundle exec ruby test.rb -r myValue -o myOptionalValue +``` + +Output + +```bash + {:required=>"myValue", :optional=>"myOptionalValue", :flag=>false} +``` + +`flag` argument + +```bash +bundle exec ruby test.rb -r myValue -f +``` + +Output + +```bash + {:required=>"myValue", :optional=>nil, :flag=>true} +``` + ## Development -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +After checking out the repository run -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +```bash +bundle install +``` +And then run the tests to check that everything is working as expected. + +```bash +ruby tests/test_easy_options_parser.rb +``` + +Remember if you are contributing, create and run the tests before pull request. + ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/easy_opt_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. +Bug reports and pull requests are welcome on Gitlab at [https://gitlab.com/gonzalez.martin90/easy-option-parser](https://gitlab.com/gonzalez.martin90/easy-option-parser). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).