carlobaldassi / argparse.jl Goto Github PK
View Code? Open in Web Editor NEWPackage for parsing command-line arguments to Julia programs.
License: Other
Package for parsing command-line arguments to Julia programs.
License: Other
Hello,
I wonder if someone ever tried to port this library to Julia 0.7/1.0
I did #67 expecting to trigger FemtoCleaner but it doesn't seem to be the case.
I wonder if it was installed.
Kind regards
This library is excellent but I just realized that it seems to be really inconvenient to run Julia as a traditional command-line program (i.e. Julia is really tailored towards REPL usage). It seems that as soon as the process exits, the compilation results will be lost and the next invocation of julia
will need to perform the compilation all over again? The startup time will be very long compared with just loading the module in the REPL and then calling its functions afterwards.
However, if I call functions within a REPL, I can't really perform argument parsing with flags and show help messages, in the style of a traditional command line program. I can only call functions with the correct order of arguments.
I just wonder if there's a way to also use this library within a REPL environment? It seems to be really a pity that one cannot enjoy both speed and argument-parsing convenience with Julia until binary executables can be produced. Am I understanding the situation correctly?
Bonjour,
I'd like to be able to enter one of the shortest unambiguous abbreviation in place of a command name. As it doesn't seam possible, is it possible to add some alias to command names?
I've tried the following code but it is rejected:
@add_arg_table s begin
"generate", "gen", "g"
action = "command"
help = "..."
"eval", "ev", "e"
action = "command"
help = "..."
end
But this raise the following error :
ERROR: LoadError: only options can have multiple names
Regard,
-- Maurice
Although it is unusual sometimes positional arguments can start with a hypen. I'll demonstrate below using the file example.jl
:
using ArgParse
settings = ArgParseSettings()
@add_arg_table settings begin
"--opt"
default = ""
"arg"
required = true
end
parsed_args = parse_args(ARGS, settings)
println(parsed_args)
When using this simple Julia file I can run it as follows which produces the expected result:
$ julia example.jl -a
unrecognized option -a
usage: example.jl [--opt OPT] arg
However -a
should be treated as a positional argument if it occurs after a --
:
$ julia example.jl -- -a
unrecognized option -a
usage: example.jl [--opt OPT] arg
But unfortunately this is not the behaviour. For reference see the Python argparse documentation section "Arguments containing -"
I'm using the following overloads for parse_item
, which allow me to pass in unevaluated expressions like log(2)
or 3*6^2
. They seem to be a bit more flexible that what's currently in master, and allow me to pass in custom types a bit more easily. I'm not sure if there are security or other performance implications, however, compared to what's currently in use.
Lines 1513 to 1515 in 37e91f4
Possible change:
ArgParse.parse_item(::Type{Vector{T}}, x::AbstractString) where {T} =
eval(parse(x))::Vector{T}
ArgParse.parse_item(::Type{T}, x::AbstractString) where {T<:Real} =
eval(parse(x))::T
On Julia 0.6 running ArgParse 0.5.0
using ArgParse
struct Foo end
function ArgParse.parse_item(::Type{Foo}, x::AbstractString)
return Foo()
end
settings = ArgParseSettings(description = "Argparse Test")
@add_arg_table settings begin
"--foo"
arg_type = Foo
required = true
nargs = '+'
end
argsDict = parse_args(settings)
Reports too many arguments when running julia foo.jl --foo foo bar
, but works fine if arg_type is replaced with String.
I would like to make it so that if a user passes in an unrecoginized option by name,
I can set it so it is just added, as a string (or maybe eval'd, or maybe handled with a user defined function?) to the returned dict.
This is not always desired, but i would like setting for it.
I can make a PR if I can get some pointers
using ArgParse
argparsesettings = ArgParseSettings()
@add_arg_table argparsesettings begin
"--opt", "-o"
help = "another option with an argument"
arg_type = Int
default = 0
end
parse_args(["--opt=4", "--bonus=71"], argparsesettings)
I would like it to be come back with:
Dict{Symbol,Any} with 1 entry:
:opt => 4,
:bonus=>"71"
The following code does not work as expected:
using ArgParse
function main(args)
s = ArgParseSettings()
@add_arg_table s begin
"--argument", "-a"
nargs = '?'
arg_type = String
constant = "testarg"
"--option", "-o"
nargs = '?'
arg_type = String
constant = "testopt"
"--parameter", "-p"
nargs = '?'
arg_type = String
constant = "testpar"
end
parsed_args = parse_args(s)
println("Parsed args:")
for (key,val) in parsed_args
println(" $key => $(repr(val))")
end
end
main(ARGS)
Here are some output examples:
$ julia testargparse.jl -aop
Parsed args:
parameter => nothing
option => nothing
argument => "op"
$ julia testargparse.jl -a -o -p
Parsed args:
parameter => "testpar"
option => nothing
argument => "-o"
$ julia testargparse.jl --argument --object --parameter
Parsed args:
parameter => "testpar"
option => nothing
argument => "--object"
This is the expected behavior:
$ julia testargparse.jl -aop
Parsed args:
parameter => "testpar"
option => "testopt"
argument => "testarg"
Any plans on adding mutual exclusion? See Python's argparse for an example.
Hi, I was wondering how much effort it would be to add support for subcommands (similar to git)? That way we'd be able to run both of the following from the same file.
julia filename.jl convert filename --from format1 --to format2
# OR
julia filename.jl validate filename
Thoughts?
any plans to fix for 0.5?
Expected behavior: on supplying 0.5
for an arugment which requires Real
, ArgParse
should accept this.
Actual behavior: ArgParse
produces an error that reports "invalid argument"
Minimal reproducible example:
test_function.jl
:
using ArgParse
function main(args)
s = ArgParseSettings("some function")
@add_arg_table! s begin
"x"
arg_type = Real
default = 0.5
help = "input"
end
parsed_args = parse_args(args, s)
println("Parsed args:")
for (key,val) in parsed_args
println(" $key => $(repr(val))")
end
end
main(ARGS)
runing with julia test_function.jl 0.5
produces the following output:
invalid argument: 0.5 (conversion to type Real failed; you may need to overload
ArgParse.parse_item; the error was: MethodError(tryparse, (Real, "0.5"), 0x0000000000006a06))
usage: Bifurcation.jl [x]
However, in an open julia session I can write Real(0.5)
with no problems.
Platform information:
This is an enhancement only, and not related to functionality.
For easier viewing/printing of the options, I think it would be neat to use an OrderedDict from the DataStructures package instead of a Dict. This will preserve the order of the arguments when the dictionary is read after creation. This would make the loop
for (arg,val) in parsed_args
println(" $arg => $val")
end
print the output in the same order as the arguments were given.
Currently, it removes all quotes from """this is a "complex" string"""" to "this is a complex string"
Using ArgParse with Julia 0.4.0 is producing the following warnings:
WARNING: ntuple(n::Integer,f::Function) is deprecated, use ntuple(f,n) instead.
WARNING: require
is deprecated, use using
or import
instead
I got the error message
ERROR: ArgParse: fetch failed to get commit 7e0f30e, please file an issue at https://github.com/carlobaldassi/ArgParse.jl/issues
in fetch(::Base.LibGit2.GitRepo, ::String, ::String) at ./pkg/write.jl:25
in #3 at ./pkg/write.jl:53 [inlined]
in with(::Base.Pkg.Write.##3#4{String,String}, ::Base.LibGit2.GitRepo) at ./libgit2/types.jl:638
in resolve(::Dict{String,Base.Pkg.Types.VersionSet}, ::Dict{String,Dict{VersionNumber,Base.Pkg.Types.Available}}, ::Dict{String,Tuple{VersionNumber,Bool}}, ::Dict{String,Base.Pkg.Types.Fixed}, ::Dict{String,VersionNumber}, ::Set{String}) at ./pkg/entry.jl:537
in update(::String, ::Set{String}) at ./pkg/entry.jl:458
in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}})() at ./pkg/dir.jl:31
in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}}, ::String) at ./file.jl:59
in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}}, ::String) at /Applications/Julia.app/Contents/Resources/julia/lib/julia/sys.dylib:?
in #cd#1(::Array{Any,1}, ::Function, ::Function, ::String, ::Vararg{Any,N}) at ./pkg/dir.jl:31
in update() at ./pkg/pkg.jl:210
while upgrading ArgParse from v0.4.0 to v0.5.0.
My first issue. Thanks, a lot. Niklas
The code:
using ArgParse
s = ArgParseSettings()
@add_arg_table s begin
"--opt"
help = "an option with an argument"
end
parsed_args = parse_args(ARGS, s)
println(parsed_args)
When given a (quoted) argument with a space inside, returns an error:
$ julia t.jl --opt "test test2"
too many arguments
usage: t.jl [--opt OPT]
INFO: Testing ArgParse
ERROR: LoadError: LoadError: There was an error during testing
in record(::Base.Test.FallbackTestSet, ::Base.Test.Fail) at .\test.jl:397
in do_test(::Base.Test.Returned, ::Expr) at .\test.jl:281
in include_from_node1(::String) at .\loading.jl:488
in macro expansion; at C:\Users\julia\AppData\Local\JuliaPro-0.5.0.1\pkgs-0.5.0.1\v0.5\ArgParse\test\runtests.jl:8 [inlined]
in anonymous at .\<missing>:?
in include_from_node1(::String) at .\loading.jl:488
in process_options(::Base.JLOptions) at .\client.jl:262
in _start() at .\client.jl:318
while loading C:\Users\julia\AppData\Local\JuliaPro-0.5.0.1\pkgs-0.5.0.1\v0.5\ArgParse\test\argparse_test8.jl, in expression starting on line 36
while loading C:\Users\julia\AppData\Local\JuliaPro-0.5.0.1\pkgs-0.5.0.1\v0.5\ArgParse\test\runtests.jl, in expression starting on line 5
==============================[ ERROR: ArgParse ]===============================
failed process: Process(`'C:\Users\julia\AppData\Local\JuliaPro-0.5.0.1\Julia-0.5.0\bin\julia' -Cx86-64 '-JC:\Users\julia\AppData\Local\JuliaPro-0.5.0.1\Julia-0.5.0\lib\julia\sys.dll' --compile=yes --depwarn=yes --check-bounds=yes --code-coverage=none --color=no --compilecache=yes 'C:\Users\julia\AppData\Local\JuliaPro-0.5.0.1\pkgs-0.5.0.1\v0.5\ArgParse\test\runtests.jl'`, ProcessExited(1)) [1]
================================================================================
Hi,
Is there a way to store arg as const x = 123
, as opposed to store it as global x = 123
? I read the docs, it mention constant
but it is always connected with a value stored if nothing were passed. The point is I read computation values from command line, and I want them to be stored as const
so to speed up my computation.
PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.
Tests pass.
Tests fail, but package loads.
Tests pass.
means that PackageEvaluator found the tests for your package, executed them, and they all passed.
Tests fail, but package loads.
means that PackageEvaluator found the tests for your package, executed them, and they didn't pass. However, trying to load your package with using
worked.
Special message from @IainNZ: This change may be due to breaking changes to Dict
in JuliaLang/julia#8521
This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.
Test log:
>>> 'Pkg.add("ArgParse")' log
INFO: Installing ArgParse v0.2.9
INFO: Installing Options v0.2.2
INFO: Installing TextWrap v0.1.3
INFO: Package database updated
>>> 'using ArgParse' log
WARNING: deprecated syntax "(Symbol=>Int)[]" at /home/idunning/pkgtest/.julia/v0.4/Options/src/Options.jl:53.
Use "Dict{Symbol,Int}()" instead.
WARNING: deprecated syntax "(String=>Any)[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:146.
Use "Dict{String,Any}()" instead.
WARNING: deprecated syntax "(String=>Vector{Any})[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1336.
Use "Dict{String,Vector{Any}}()" instead.
WARNING: deprecated syntax "(String=>Any)[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1451.
Use "Dict{String,Any}()" instead.
WARNING: deprecated syntax "(Symbol=>Any)[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1833.
Use "Dict{Symbol,Any}()" instead.
Julia Version 0.4.0-dev+998
Commit e24fac0 (2014-10-07 22:02 UTC)
Platform Info:
System: Linux (x86_64-unknown-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
>>> test log
WARNING: deprecated syntax "(Symbol=>Int)[]" at /home/idunning/pkgtest/.julia/v0.4/Options/src/Options.jl:53.
Use "Dict{Symbol,Int}()" instead.
WARNING: deprecated syntax "(String=>Any)[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:146.
Use "Dict{String,Any}()" instead.
WARNING: deprecated syntax "(String=>Vector{Any})[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1336.
Use "Dict{String,Vector{Any}}()" instead.
WARNING: deprecated syntax "(String=>Any)[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1451.
Use "Dict{String,Any}()" instead.
WARNING: deprecated syntax "(Symbol=>Any)[]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1833.
Use "Dict{Symbol,Any}()" instead.
WARNING: deprecated syntax "(String=>Any)[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl:47.
Use "Dict{String,Any}(a=>b, ...)" instead.
WARNING: deprecated syntax "(String=>Any)[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl:48.
Use "Dict{String,Any}(a=>b, ...)" instead.
WARNING: deprecated syntax "(String=>Any)[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl:49.
Use "Dict{String,Any}(a=>b, ...)" instead.
WARNING: deprecated syntax "(String=>Any)[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl:50.
Use "Dict{String,Any}(a=>b, ...)" instead.
WARNING: deprecated syntax "(String=>Any)[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl:52.
Use "Dict{String,Any}(a=>b, ...)" instead.
WARNING: deprecated syntax "(String=>Any)[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl:53.
Use "Dict{String,Any}(a=>b, ...)" instead.
ERROR: test error in expression: ap_test1([]) == $(Expr(:typed_dict, :(String=>Any), :("opt1"=>nothing), :("opt2"=>nothing), :("arg1"=>nothing)))
`Dict{Symbol,Int64}` has no method matching Dict{Symbol,Int64}(::(Symbol,Symbol,Symbol), ::(Int64,Int64,Int64))
in Options at /home/idunning/pkgtest/.julia/v0.4/Options/src/Options.jl:45
in parse_args_unhandled at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1537
in parse_args at /home/idunning/pkgtest/.julia/v0.4/ArgParse/src/ArgParse.jl:1430
in ap_test1 at /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl:33
in anonymous at test.jl:83
in do_test at test.jl:47
in anonymous at no file:47
in include at ./boot.jl:245
in include_from_node1 at ./loading.jl:128
in anonymous at no file:8
in include at ./boot.jl:245
in include_from_node1 at loading.jl:128
in process_options at ./client.jl:293
in _start at ./client.jl:362
in _start_3B_3789 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
while loading /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/argparse_test1.jl, in expression starting on line 32
while loading /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/runtests.jl, in expression starting on line 5
Running argparse_test1
INFO: Testing ArgParse
==============================[ ERROR: ArgParse ]===============================
failed process: Process(`/home/idunning/julia04/usr/bin/julia /home/idunning/pkgtest/.julia/v0.4/ArgParse/test/runtests.jl`, ProcessExited(1)) [1]
================================================================================
INFO: No packages to install, update or remove
ERROR: ArgParse had test errors
in error at error.jl:21
in test at pkg/entry.jl:719
in anonymous at pkg/dir.jl:28
in cd at ./file.jl:20
in cd at pkg/dir.jl:28
in test at pkg.jl:68
in process_options at ./client.jl:221
in _start at ./client.jl:362
in _start_3B_3789 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
>>> end of log
Hello,
Maybe tests should be include in testset
so we could have a convenient summary of all tests and see more easily which are failing.
https://docs.julialang.org/en/v0.7/stdlib/Test/#Test.@testset
Kind regards
It would be very useful to be able to use argument parsing even when in REPL mode (especially during development). In particular, it would be great if the following two things were supported:
A) passing in of "command line" arguments when in the REPL
B) not exiting Julia when in the REPL (exit_when_done
)
I have asked a related question on StackOverflow which has helped me to create a workaround for point A). I can now pass in "command line" arguments in the REPL by assigning all parameters to a variable ARGS
(e.g. ARGS = "--help"
) and then call parse_args
via
if isinteractive()
args = parse_args(split(ARGS), s, as_symbols=true)
else
args = parse_args(s, as_symbols=true)
end
For point B), would it be a reasonable idea to replace
exit_when_done && exit(0)
by
exit_when_done && !isinteractive() && exit(0)
?
I am trying to catch an ArgParseError thrown due to a bad argument but can't seem to do it:
using ArgParse
function foo(args)
opts = nothing
isa(args, AbstractString) && (args=split(args))
s = ArgParseSettings()
@add_arg_table s begin
("--seed"; arg_type=Int; default=42)
end
try
opts = parse_args(args,s)
catch
info("Caught something")
finally
info("Finally this")
end
return opts
end
julia> foo("--seed 10")
INFO: Finally this
Dict{AbstractString,Any} with 1 entry:
"seed" => 10
!julia> foo("--feed 10")
INFO: Rethrowing ArgParse.ArgParseError("unrecognized option --feed")
in parse_args at /home/nlg-05/dy_052/knet/dev/.julia/v0.4/ArgParse/src/ArgParse.jl:1528
in foo at /home/nlg-05/dy_052/knet/dev/examples/foo3.jl:11
unrecognized option --feed
usage: <PROGRAM> [--seed SEED]
Process julia exited abnormally with code 1 at Fri Dec 4 08:02:30 2015
Hello,
A nice improvement could be to be able to run tests individually.
Kind regards
Right now the ArgParseError
has one field: text
.
It would be useful if it have some extra field.
E.g. if you gave an extra named argument with an unexpected name,
it should be possible to findout what that name and value was.
The following output for a missing input file is not super helpful:
out of range input for --chip: examples/test3.bed
Would be better with file not found: examples/test3.bed
.
Is it possible not to exit Julia after displaying the help string? I saw a keyword argument in the function to this effect but there is no way to call it with the non-default setting. I use the debug_handler for not quitting after errors. This is useful e.g. while debugging or in an IJulia notebook.
julia> using ArgParse
WARNING: requiring "Options" in module "Main" did not define a corresponding module.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 55
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
in anonymous at null:-1
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 208
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Base.None is deprecated, use Union{} instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Base.None is deprecated, use Union{} instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Base.None is deprecated, use Union{} instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 516
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 874
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 874
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 889
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 1456
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 1456
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.Nothing is deprecated, use Void instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/ArgParse/src/ArgParse.jl, in expression starting on line 1456
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.String is deprecated, use AbstractString instead.
julia> versioninfo(true)
Julia Version 0.4.0-rc2
Commit fa52609* (2015-09-18 17:51 UTC)
- ArgParse 0.2.12 master
I cannot update ArgParse under Julia 0.6.3:
julia> Pkg.update()
INFO: Updating METADATA...
INFO: Updating Options master...
INFO: Computing changes...
ERROR: ArgParse can't be installed because it has no versions that support 0.6.3 of julia. You may need to update METADATA by running `Pkg.update()`
I removed it successfully, now I cannot add it back:
julia> Pkg.add("ArgParse")
ERROR: ArgParse can't be installed because it has no versions that support 0.6.3 of julia. You may need to update METADATA by running `Pkg.update()`
How can I install or update this package?
I'd like to be able to specify a different type and/or metavar for each argument in a mulit-argument option. Here's a use case that demonstrates my request:
@add_arg_table s begin
"--point"
nargs = 3
metavar = ["X", "Y", "LABEL"]
arg_type = [Float64, Float64, AbstractString]
end
The best I can do is to put metavar = "X"
, which results in help messages of --point X X
, which is not what I want. Further, metavar = "X_THEN_Y"
doesn't work either, since it results in --point X_THEN_Y X_THEN_Y
.
Of course, this problem could be solved by adding more arguments, but my program already has a bunch of other arguments and I don't want this particular feature to take up 3 more.
If there's some support for this idea out there, I may be able to implement it myself within a few weeks.
I have noticed using ArgParse takes almost 2s to parse command line arguments. Here are timings for Julia 0.5.0 on Mac OS. Timings are similar on linux (same julia version).
$ time julia argparse_example3.jl
required argument arg1 was not provided
usage: argparse_example3.jl [--opt1 [OPT1]] [-k] arg1 arg1 [arg2...]
1.932u 0.175s 0:02.05 102.4% 0+0k 0+6io 53pf+0w
I have the following scenario: I'm developing a Julia file, which is meant to be run from the command line, but for debugging purposes and such, I aim to make it possible to have that same file to be possible to include()
into a Jupyter environment.
This does not work, as the file crashes the IJulia kernel, and it restarts. I would expect the behaviour to be that if file is run without any arguments (called in by include()
) runs with only default values.
This may be on the border on what you wish to support in ArgParse.jl
, and I will try and find a work-around, but I just thought it would be good to have documentation of the issue.
Anyhow, a minimal example that demonstrates the issue I found to be
using ArgParse
s = ArgParseSettings()
@add_arg_table s begin
"--solver", "-s"
help = "select solver"
default = "simple"
end
parse_args(s)
Executing this in a Jupyter notebook with an IJulia kernel, then the IJulia kernel is killed by the parse_args(s)
line, without an error in the Jupyter output, and the kernel is restarted.
I'm on Julia v1.1.0 (Commit 110d8cb*), ArgParse v0.6.2, IJulia v1.18.0 (which are all the latest pulled in by update).
Is there an equivalent to python argparse choice, e.g.:
parser.add_argument ('--rate', choices=('1/3', '1/2', '2/3', '3/4', '3/5', '4/5', '5/6', '7/9', '8/9', '9/10', '25/36', '26/45'), default='2/3')
With newer versions of julia, is the Options package still needed or can ArgParse be rewritten to remove the dependency?
See Python's argparse
method add_mutually_exclusive_group()
: https://docs.python.org/3.6/howto/argparse.html#conflicting-options
I have a custom type LogConfig
which I'd like to add as an ArgParse argument. By default, using arg_type=LogConfig
causes "invalid argument: error (must be of type CommandLine.LogConfig)". I've managed to get things working by overloading ArgParse.parse_item
with my custom type, but it's not clear from the docs that this is the right thing.
Here's a cut down example of what I'm trying to do. Run as, for example, julia test_custom_type.jl --loglevel warning
.
using Logging
using ArgParse
type LogConfig
level::Logging.LogLevel
end
function LogConfig(logconf::String)
if logconf == "error" return LogConfig(Logging.ERROR)
elseif logconf == "warning" return LogConfig(Logging.WARNING)
elseif logconf == "info" return LogConfig(Logging.INFO)
elseif logconf == "debug" return LogConfig(Logging.DEBUG)
else return LogConfig(Logging.INFO) # default
end
end
ArgParse.parse_item(::Type{LogConfig}, logconf::String) = LogConfig(logconf)
settings = ArgParseSettings()
@add_arg_table settings begin
"--loglevel"
help = "Logging verbosity none|error|warning|info|debug [info]"
arg_type = LogConfig
default = LogConfig("info")
end
args = parse_args(settings)
show(args["loglevel"])
println()
Related, I noticed that parse_item(it_type::Type, x::String)
calls parse()
internally as eval(parse(x)[1])
. After squinting at this for a while I still don't understand exactly what it's trying to achieve with the indexing, but I do wonder whether it implies arbitrary code execution during command line parsing, which seems like a bad thing from a security point of view.
In an effort to minimize/eliminate the delay before -h
output (about 3 or 4 seconds in my case) I followed the advice in #37 (comment) but wound up at the below error. This is with ArgParse master as well as with whatever is installed with simply ] add ArgParse
:
julia> # This command will use the `runtest.jl` of `ArgParse` + `SnoopCompile` to find out what functions to precompile!
# `force = false` to not force overwriting Julia's current system image
compile_package("ArgParse", "SnoopCompile", force = false, reuse = false)
Launching new julia process to run commands...
Test Summary: | Pass Total
test 01 | 32 32
Test Summary: | Pass Total
test 02 | 80 80
Test Summary: | Pass Total
test 03 | 32 32
Test Summary: | Pass Total
test O4 | 14 14
Test Summary: | Pass Total
test 05 | 40 40
Test Summary: | Pass Total
test 06 | 13 13
Test Summary: | Pass Total
test 07 | 5 5
Test Summary: | Pass Total
test 08 | 11 11
Test Summary: | Pass Total
test 09 | 3 3
Test Summary: | Pass Total
test 10 | 44 44
done.
ERROR: MethodError: no method matching normpath(::Nothing, ::String, ::String)
Closest candidates are:
normpath(::AbstractString, ::AbstractString...) at path.jl:272
Stacktrace:
[1] (::getfield(PackageCompiler, Symbol("##25#28")))(::Tuple{String,String}) at /Users/pat/.julia/packages/PackageCompiler/BBtC7/src/snooping.jl:59
[2] map(::getfield(PackageCompiler, Symbol("##25#28")), ::Tuple{Tuple{String,String},Tuple{String,String}}) at ./tuple.jl:163
[3] snoop_userimg(::String, ::Tuple{String,String}, ::Vararg{Tuple{String,String},N} where N) at /Users/pat/.julia/packages/PackageCompiler/BBtC7/src/snooping.jl:54
[4] #compile_package#39(::Bool, ::Bool, ::Bool, ::Nothing, ::Function, ::Tuple{String,String}, ::Vararg{Tuple{String,String},N} where N) at /Users/pat/.julia/packages/PackageCompiler/BBtC7/src/PackageCompiler.jl:105
[5] (::getfield(PackageCompiler, Symbol("#kw##compile_package")))(::NamedTuple{(:force, :reuse),Tuple{Bool,Bool}}, ::typeof(compile_package), ::Tuple{String,String}, ::Vararg{Tuple{String,String},N} where N) at ./none:0
[6] #compile_package#36(::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol},NamedTuple{(:force, :reuse),Tuple{Bool,Bool}}}, ::Function, ::String, ::Vararg{String,N} where N) at /Users/pat/.julia/packages/PackageCompiler/BBtC7/src/PackageCompiler.jl:92
[7] (::getfield(PackageCompiler, Symbol("#kw##compile_package")))(::NamedTuple{(:force, :reuse),Tuple{Bool,Bool}}, ::typeof(compile_package), ::String, ::Vararg{String,N} where N) at ./none:0
[8] top-level scope at none:0
julia> versioninfo()
Julia Version 1.0.1
Commit 0d713926f8 (2018-09-29 19:05 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
(v1.0) pkg> st
Status `~/.julia/environments/v1.0/Project.toml`
[cc31668c] ApplicationBuilder v0.0.0 [`~/.julia/dev/ApplicationBuilder`]
[c7e460c6] ArgParse v0.6.1+ #master (https://github.com/carlobaldassi/ArgParse.jl.git)
[34da2185] Compat v1.3.0
[0c46a032] DifferentialEquations v5.3.1
[7073ff75] IJulia v1.13.0
[682c06a0] JSON v0.19.0
[ee78f7c6] Makie v0.9.0
[9b87118b] PackageCompiler v0.5.0
[91a5bcdd] Plots v0.20.6
[438e738f] PyCall v1.18.5
[295af30f] Revise v0.7.12
[b8865327] UnicodePlots v0.3.1
[c2297ded] ZMQ v1.0.0
I would like to be able to insert a line break in the epilog to provide visual separation for different examples. Question first raised at https://groups.google.com/forum/#!topic/julia-users/ZvJmdwJmuwo
Perhaps you could provide support for Markdown in your documentation strings? Something like
s.epilog = md""" A Markdown string"""
Thanks for the great package that I make heavy use of!
The currently tagged version of the package doesn't work on Julia 0.7, but it appears master does.
In python argparse, I've been using ConfigureAction, which is an action that acts like gnu configure. If I have:
'--blah', action=ConfigureAction...
Then I can specify:
--blah, --no-blah, --with-blah, --without-blah
The code for ConfigureAction is not distributed as a standard part of argparse.py, but I can supply it if it helps.
If you create the file "test.jl" containing the example provided in the documentation:
@everywhere using ArgParse
@everywhere function parse_commandline()
s = ArgParseSettings()
@add_arg_table s begin
"--opt1"
help = "an option with an argument"
"--opt2", "-o"
help = "another option with an argument"
arg_type = Int
default = 0
"--flag1"
help = "an option without argument, i.e. a flag"
action = :store_true
"arg1"
help = "a positional argument"
end
return parse_args(s)
end
function main()
@everywhere parsed_args = parse_commandline()
println("Parsed args:")
for pa in parsed_args
println(" $(pa[1]) => $(pa[2])")
end
@everywhere test=parsed_args["opt1"]
end
main()
Then running the command julia test.jl --opt1 test
runs as intended, but julia -p 2 test.jl --opt1 test
returns the following error
-bash-4.1$ julia -p 2 test.jl --opt1 test
unrecognized option --bind-to
usage: <PROGRAM> [--opt1 OPT1] [-o OPT2] [--flag1] [arg1]
Worker 2 terminated.ERROR: ProcessExitedException()
in remotecall_fetch at multi.jl:696
in main at /raid2/labs/Koslicki_lab/koslickd/Scripts/test.jl:314
in include at boot.jl:244
in include_from_node1 at loading.jl:128
while loading /raid2/labs/Koslicki_lab/koslickd/Scripts/test.jl, in expression starting on line 32
WARNING: Forcibly interrupting busy workers
exception on 3:
keys of parse_args(s, as_symbols=true)
are strings but should be symbols
While fixing deprecations on ArgParse, the change from symbol
to Symbol
seems to break things on Julia v0.3
. The error is
Running argparse_test5
ERROR: test error during parse_args(["jump","-sbt2"],s,as_symbols=true) == $(Expr(:typed_dict, :(Symbol=>Any), :(:_COMMAND_=>:jump), :(:jump=>$(Expr(:typed_dict, :(Symbol=>Any), :(:higher=>false), :(:_COMMAND_=>:som), :(:som=>$(Expr(:typed_dict, :(Symbol=>Any), :(:t=>2), :(:b=>true)))))))))
type cannot be constructed
in convert_to_symbols at /home/travis/.julia/v0.3/ArgParse/src/ArgParse.jl:1987
in parse_args at /home/travis/.julia/v0.3/ArgParse/src/ArgParse.jl:1555
in anonymous at test.jl:62
in do_test at test.jl:37
in anonymous at no file:123
in include at ./boot.jl:245
in include_from_node1 at ./loading.jl:128
in anonymous at no file:8
in include at ./boot.jl:245
in include_from_node1 at loading.jl:128
in process_options at ./client.jl:285
in _start at ./client.jl:354
while loading /home/travis/.julia/v0.3/ArgParse/test/argparse_test5.jl, in expression starting on line 58
while loading /home/travis/.julia/v0.3/ArgParse/test/runtests.jl, in expression starting on line 5
How could I not break things on Julia v0.3
and yet make the deprecations go away?
Hi, is there any plan to support autogeneration of the negation of a boolean flag? That is, if I want to accept both --foo
and --no-foo
to enable and disable foo
, I could write something like
s = ArgParseSettings()
@add_arg_table s begin
"--foo"
action = :store_true
"--no-foo"
dest_name = "foo"
action = :store_false
end
But it would be nice to have a shorthand. Here's how python click does it, for example: http://click.pocoo.org/5/options/#boolean-flags
CC @janzill
I get the following warning on the latest Julia:
WARNING: [a,b] concatenation is deprecated; use [a;b] instead
which can be fixed by making this small change on line 1347:
< opt_str1 = join([["-"*x for x in f.short_opt_name], ["--"*x for x in f.long_opt_name]], ", ")
---
> opt_str1 = join([["-"*x for x in f.short_opt_name]; ["--"*x for x in f.long_opt_name]], ", ")
I was recently trying to do something like this
@add_arg_table(settings
, "--argname", arg_type=Symbol, default=:def
)
This fails, because the method convert(::Type{Symbol}, ::String)
isn't defined. However, given that Symbol(::String)
is defined, I think it would be sensible for ArgParse to use that. So I would propose something like replacing
parse_item(it_type::Type{T}, x::AbstractString) where {T} = convert(T, x)
with
parse_item(::Type{T}, x::AbstractString) where {T} = applicable(T, x) ? T(x) : convert(T, x)
This would allow parsed_args
to be passed to functions directly as named arguments:
function myfunc(;arg1=1, arg2="test", args...)
...
end
function main()
args = parse_args(s)
myfunc(args...)
...
end
I'm interested in setting a flag argument as required, could this be added?
something along the lines of:
"--input"
help = "input file"
nargs = 1
required = true
arg_type = String
dest_name = "input_file"
"--output"
help = "output file"
nargs = 1
required = true
arg_type = String
dest_name = "output_file"
This would be similar in behavior to argparse in Python: https://docs.python.org/dev/library/argparse.html#required
The following code:
s = ArgParseSettings("Test description.\n\nExamples:\nexample1\nexample2")
outputs the description as follows:
Test description.
Examples: example1 example2
while I would have expected:
Test description.
Examples:
example1
example2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.