Some commands need to support numeric aliases, but thor currently (as of 0.20.0) cannot.
We have a command that accepts options to select one or more stages of a process: eg: --stage1, --stage2, ..., --stage5.
We would like to be able to specify -1, -2, ..., -5, which, when used with combined single-character options, could be specified like this: -125.
Of course, we understand that a workaround for this lack is to use --stage=STAGES, where STAGES are one or more numbers.
However, there does not appear to be any syntactical reason for not supporting numeric aliased options, so this appears to be simply an oversight in the original implementation.
A possible quick fix might be:
diff --git a/lib/thor/parser/options.rb b/lib/thor/parser/options.rb
index 7459978..4b73a38 100644
--- a/lib/thor/parser/options.rb
+++ b/lib/thor/parser/options.rb
@@ -1,9 +1,9 @@
class Thor
class Options < Arguments #:nodoc: # rubocop:disable ClassLength
LONG_RE = /^(--\w+(?:-\w+)*)$/
- SHORT_RE = /^(-[a-z])$/i
+ SHORT_RE = /^(-[a-z0-9])$/i
EQ_RE = /^(--\w+(?:-\w+)*|-[a-z])=(.*)$/i
- SHORT_SQ_RE = /^-([a-z]{2,})$/i # Allow either -x -v or -xv style for single char args
+ SHORT_SQ_RE = /^-([a-z0-9]{2,})$/i # Allow either -x -v or -xv style for single char args
SHORT_NUM = /^(-[a-z])#{NUMERIC}$/i
OPTS_END = "--".freeze
Some commands need to support numeric aliases, but thor currently (as of 0.20.0) cannot.
We have a command that accepts options to select one or more stages of a process: eg:
--stage1,--stage2, ...,--stage5.We would like to be able to specify
-1,-2, ...,-5, which, when used with combined single-character options, could be specified like this:-125.Of course, we understand that a workaround for this lack is to use
--stage=STAGES, whereSTAGESare one or more numbers.However, there does not appear to be any syntactical reason for not supporting numeric aliased options, so this appears to be simply an oversight in the original implementation.
A possible quick fix might be: