Comments (6)
Hey @simendsjo ,
What is the value associated with the -c|--clip
option, when you only invoke these?
cmd foo
cmd -c foo
cmd -c1 foo
I assume there's a default value associated with the -c|--clip
option, is that correct? If that's the case, can you simply use a regular int
option with a default value?
from clingon.
I assume there's a default value associated with the -c|--clip option, is that correct? If that's the case, can you simply use a regular int option with a default value?
The problem is that I want missing, present and value-set, but an int option can only give me missing (default) and value set, but not "present but without value".
I need to know that the option was missing as that should show all lines to stdout. I don't care what value is stored in clip as long as it's not a positive integer in this case.
clip | result |
---|---|
nil | |
-c | 1 |
-c2 | 2 |
from clingon.
Hey @simendsjo ,
Maybe I'm not able to understand the use case, but wouldn't something like this work?
(defun clip/options ()
(list
(clingon:make-option :integer
:short-name #\c
:long-name "clip"
:description "the --clip option"
:key :clip/option)))
(defun clip/handler (cmd)
(let ((opt-value (clingon:getopt cmd :clip/option 1))
(opt-is-set (clingon:opt-is-set-p cmd :clip/option))
(args (clingon:command-arguments cmd)))
(format t "--clip option is set: ~A~%" opt-is-set)
(format t "--clip value is: ~A~%" opt-value)
(format t "free args: ~A~%" args)))
(defun clip/command ()
(clingon:make-command
:name "clip"
:description "clip command"
:handler #'clip/handler
:options (clip/options)))
Option is not specified on command-line, and it's value is 1
.
$ cmd foo
--clip option is set: NIL
--clip value is: 1
free args: (foo)
Option is specified on the command-line.
$ cmd -c 42 foo
--clip option is set: T
--clip value is: 42
free args: (foo)
Supporting a command-line like this in my opinion is very ambiguous, where -c
option might receive a value, or not.
$ cmd -c foo
In this case it's not clear whether -c
is a flag (option with no arguments), or whether foo
is the value associated with -c
option.
from clingon.
Maybe I'm not able to understand the use case, but wouldn't something like this work?
No, unfortunately, because cmd -c foo
will consume foo
even though it's not an integer.
Supporting a command-line like this in my opinion is very ambiguous, where -c option might receive a value, or not.
Yes, I totally agree, but I'm trying to be backwards compatible with an existing API so tools also works with my implementation.
I guess I can solve this by fetching uiop:command-line-arguments myself, look for -c not-an-integer
and change it to -c1 not-an-integer
. Quite hackish, but at least it should work.
Yes, not a very good API design :/
from clingon.
Here's my solution. Replaces "-c" with "-c1" and "--clip" with "--clip=1" if it's not followed by an integer.
And I pass the result to clingon:run
. Good enough for me :)
(cl:defun patch-args-for-clip (args cl:&aux (result (cl:copy-list args)))
(cl:dolist (spec (cl:list (cl:cons "-c" "-c1")
(cl:cons "--clip" "--clip=1"))
result)
(cl:let* ((old (cl:car spec))
(new (cl:cdr spec))
(opt (cl:member old result :test 'cl:equal))
(val (cl:cadr opt))
(int? (cl:when val (cl:parse-integer val :radix 10 :junk-allowed cl:t))))
(cl:when (cl:and opt (cl:not int?))
(cl:nsubst new old result :test 'cl:equal)))))
from clingon.
Thanks for all your support! Guess we can close this as a won't fix as it's not really a recommended API design.
from clingon.
Related Issues (19)
- [Question] Having a subcommand that doesn't take any arguments or options HOT 2
- Trying to handle parse errors inside run (to use unknown options as free args) HOT 2
- Proposal: running clingon:run and not exit-ing when in a dumb terminal (like Slime) HOT 7
- Desactivating quit/exit at the REPL if desired HOT 8
- option-derive-error output doesn't mention the option name that produced the error HOT 3
- About line breaks in the description HOT 3
- Question: Clingon and buildapp? HOT 4
- Support named positional arguments HOT 1
- How can I add a new option type like Python click's nargs? HOT 2
- completions.bash doesn't work. HOT 4
- Documentation request HOT 1
- Searching for options in parent commands HOT 7
- Documentation about extending and adding aliases to pre-existing commands? HOT 10
- [SBCL] --help and --version print SBCL's help and version HOT 4
- --version for subcommands HOT 2
- Tags and Quicklisp HOT 1
- Simple question about README HOT 2
- Feature enhancement: float options HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clingon.