You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
This discussion was converted from issue #622 on May 12, 2023 22:29.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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
, whereSTAGES
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:
Beta Was this translation helpful? Give feedback.
All reactions