denisdefreyne / cri

A tool for building commandline applications
MIT License
120 stars 19 forks source link

Feature: Parameters with default value #75

Open denisdefreyne opened 6 years ago

denisdefreyne commented 6 years ago

Idea: allow parameters to be defined with a default value. For example:

param :host
param :port, transform: method(:Integer), default: 3000

For simplicity, allow parameters with a default value to only appear at the end. The following would therefore not be possible:

param :foo, default: 'xxx'
param :bar
param :foo
param :bar, default: 'xxx'
param :qux
param :abc, default: 'yyy'

I image that this restriction will be fine, because the CLI will become complicated to use otherwise anyway.

andkirby commented 6 years ago

Guys, has this feature been released?... I'm getting an error on set default:

/.../ruby-2.5.1/lib/.../cri-2.15.0/lib/cri/command_dsl.rb:173:in 
    `param': unknown keyword: default (ArgumentError)

UPD... Yeah, I guess not, here are no commits yet. It would be great to have this feature. It will allow to make a parameter make as an optional one by setting empty value like nil or ''.

denisdefreyne commented 6 years ago

@andkirby It’s not implemented yet! This GitHub issue serves as a to-do item.