rue-ryuzaki / argparse Goto Github PK
View Code? Open in Web Editor NEWArgument parser for C++
Home Page: https://launchpad.net/~golubchikov-mihail/+archive/ubuntu/cpp-argparse
License: MIT License
Argument parser for C++
Home Page: https://launchpad.net/~golubchikov-mihail/+archive/ubuntu/cpp-argparse
License: MIT License
Tracking issue for:
Current mingw job:
mingw:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
architecture: [x64, x86]
standard: [98, 11, 14, 17, 20]
steps:
- uses: actions/checkout@v2
- name: Set up MinGW
uses: egor-tensin/setup-mingw@v2
with:
platform: ${{ matrix.architecture }}
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_STANDARD=${{ matrix.standard }}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
often falls is Set up MinGW step with error:
Chocolatey v1.1.0
Upgrading the following packages:
mingw
By upgrading, you accept licenses for the packages.
mingw v8.1.0 [Approved]
mingw package files upgrade completed. Performing other installation steps.
Downloading mingw 64 bit
from 'https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z/download'
ERROR: The remote file either doesn't exist, is unauthorized, or is forbidden for url 'https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z/download'. Exception calling "GetResponse" with "0" argument(s): "The request was aborted: Could not create SSL/TLS secure channel."
This package is likely not broken for licensed users - see https://docs.chocolatey.org/en-us/features/private-cdn.
The upgrade of mingw was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\mingw\tools\chocolateyinstall.ps1'.
See log for details.
Chocolatey upgraded 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Failures
- mingw (exited 404) - Error while running 'C:\ProgramData\chocolatey\lib\mingw\tools\chocolateyinstall.ps1'.
See log for details.
Other configurations are required to build with mingw for Windows
These are the typos detected by codespell in the project
README.md:34: macroses ==> macros
README.md:35: setted ==> set
./include/argparse/argparse.hpp:85: compability ==> compatibility
./include/argparse/argparse.hpp:2499: missmatch ==> mismatch
Hi there!
It's been a while, happy holidays ๐
I recently came across an integration detail that does not conform to the specification.
It seems that it is not possible to use internal values for attribute names in calls like args.exists("long_option")
instead of args.exists("--long-option")
for an argument specified as --long-option
.
Excerpt from https://docs.python.org/3/library/argparse.html#dest
For optional argument actions, the value of dest is normally inferred from the option strings. ArgumentParser generates the value of dest by taking the first long option string and stripping away the initial
--
string. If no long option strings were supplied, dest will be derived from the first short option string by stripping the initial-
character. Any internal-
characters will be converted to_
characters to make sure the string is a valid attribute name.
Make a call to a function that requires an attribute name for an optional compound argument using explicit and internal values
I expected the calls to accept this subtlety
No response
No response
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
1.6.5
develop
branch is used.I am getting this warning with clang 13.0.0 on macos
../libs/argparse/include/argparse/argparse.hpp:97:32: warning: unknown warning group '-Wimplicit-fallthrough=', ignored [-Wunknown-warning-option]
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough="
^
1 warning generated.
% clang++ --version
Homebrew clang version 13.0.0
Target: x86_64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
Is there a pattern to access the parsed args from within a handle lambda? I thought something like this might work but it doesn't seem to.
#include <argparse/argparse.hpp>
#include <iostream>
int main(int argc, char* argv[]) {
argparse::ArgumentParser::Namespace space;
auto parser = argparse::ArgumentParser(argc, argv);
auto& subparsers = parser.add_subparsers();
auto& parser_a = subparsers.add_parser("a")
.handle([&]() {
std::cout << "bar: " << space.get<uint32_t>("bar") << std::endl;
});
parser_a.add_argument("bar");
space = parser.parse_args();
return 0;
}
AttributeError: 'Namespace' object has no attribute 'bar'
Hello!
Implicit values (from 80ab3cc ) do not work if they are followed by other positional arguments (or subparsers), the following value might have to be compared to next available arguments in order to assert if that's a custom value or another argument.
Given a parser with an implicit value optional argument --arg
and a positional argument value
:
./mybin --arg mycustomvalue 42
# works
./mybin --arg 42
# fails
The same behavior occurs in the context of subparsers.
Given a parser with an implicit value optional argument --arg
and a subparser a
:
./mybin --arg mycustomvalue a
# works
./mybin --arg a
# fails
First, thanks for awesome library. I use Python argparse a lot, then now I can use it in C++.
I have similar issue to #4, specially the second case.
The goal is use default value without any option and allow override it or disable it (or change same predefined).
./mybin
# a) default arg "a"
./mybin --no-arg
# b) where arg is disabled, set to "b" for better view
./mybin --arg x
# x) where custom arg is "x"
Python version.
p = argparse.ArgumentParser()
p.add_argument('--arg', default='a')
# _StoreAction(option_strings=['--arg'], dest='arg', nargs=None, const=None, default='a', type=None, choices=None, required=False, help=None, metavar=None)
p.add_argument('--no-arg', dest='arg', action='store_const', const='b')
# _StoreConstAction(option_strings=['--no-arg'], dest='arg', nargs=0, const='b', default=None, type=None, choices=None, required=False, help=None, metavar=None)
p.parse_args(''.split())
# Namespace(arg='a')
p.parse_args('--arg x'.split())
# Namespace(arg='x')
p.parse_args('--no-arg'.split())
# Namespace(arg='b')
I have a problem with dest
. There is a conflict or second argument overrides the first.
Of course I can use an another name add add if
to override dest
in my code after parsing. Than it's not so important issue.
Just note Python differs.
Compile and run.
For dest("--arg")
I have:
argparse::ArgumentError: argument --no-arg: conflicting dest string: --arg
For dest("arg")
I have:
./mybin
(empty) arg is ''
./mybin --no-arg
(exists) arg is 'b'
./mybin --arg x
(empty) arg is ''
In both cases.
./mybin
(exists) arg is 'a'
./mybin --no-arg
(exists) arg is 'b'
./mybin --arg x
(exists) arg is 'x'
#include "argparse.hpp"
int main(int argc, char *argv[])
{
auto parser = argparse::ArgumentParser(argc, argv);
parser.add_argument("--arg").default_value("a");
parser.add_argument("--no-arg").action("store_const").dest("arg").const_value("b");
auto const args = parser.parse_args();
std::cout << (args.exists("arg") ? "(exists)" : "(empty) ") << " arg is '" << args.get<std::string>("arg") << "'" << std::endl;
return 0;
}
argparse::ArgumentError: argument --no-arg: conflicting dest string: --arg
c++ -o mybin aa.cc
Debian testing.
1.6.4
develop
branch is used.Hello there!
A very useful library ๐
Do you plan to incorporate implicit value support in the near future?
These implicit values behave like flags and allow you to use a predefined value or specify a custom one on activation.
This is slightly different from a default value, since when the argument is not specified on the command line, no value (or a null value) is assigned to the argument.
./mybin
# where arg is disabled
./mybin --arg
# where arg is "mypredefinedvalue"
./mybin --arg mycustomvalue
# where arg is "mycustomvalue"
This is an alternative to having 2 arguments for this task using a default and a flag, such as:
./mybin --no-arg
# where arg is disabled
./mybin
# where arg is "mypredefinedvalue"
./mybin --arg mycustomvalue
# where arg is "mycustomvalue"
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.