TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Structopt for C++ – Parse command line arguments by defining a struct

85 pointsby p-ranavalmost 5 years ago

10 comments

bschwindHNalmost 5 years ago
Is &#x27;structopt&#x27; a common name for this type of argument parser library? I thought it started with the Rust library of the same name but no one has mentioned it yet...<p>In my opinion, it is _the_ way to quickly create a quality CLI.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;TeXitoi&#x2F;structopt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;TeXitoi&#x2F;structopt</a>
评论 #24187464 未加载
gwenzekalmost 5 years ago
Similar lib I made for Python: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;func-argparse&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;func-argparse&#x2F;</a><p>The nice thing with Python is that I implemented a parser from a function signature, and it also works for NamedTuple.<p>The advantage wrt to other python parser is that it uses the type annotations, instead of guessing
评论 #24185936 未加载
评论 #24184612 未加载
gomobooalmost 5 years ago
I will try this one out. Here’s a similar library that I’ve had success with before: <a href="https:&#x2F;&#x2F;github.com&#x2F;mmahnic&#x2F;argumentum" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mmahnic&#x2F;argumentum</a> I’ve also recently used <a href="https:&#x2F;&#x2F;docs.opencv.org&#x2F;trunk&#x2F;d0&#x2F;d2e&#x2F;classcv_1_1CommandLineParser.html#details" rel="nofollow">https:&#x2F;&#x2F;docs.opencv.org&#x2F;trunk&#x2F;d0&#x2F;d2e&#x2F;classcv_1_1CommandLineP...</a> from OpenCV. It’s useful when you’re already using OpenCV and don’t want to bring in another dependency.
评论 #24183670 未加载
评论 #24183861 未加载
worldsayshialmost 5 years ago
&gt; Include &lt;structopt&#x2F;app.hpp&gt; and you&#x27;re good to go.<p>I haven&#x27;t touched C++ for almost a decade but I assume there&#x27;s (still?) no obvious way that always works to include a dependency package in your build?<p>For you C++ devs, does this instruction make it obvious how to install this thing into your project?
评论 #24185770 未加载
评论 #24185213 未加载
评论 #24187046 未加载
评论 #24187163 未加载
评论 #24187732 未加载
评论 #24186232 未加载
评论 #24187161 未加载
ur-whalealmost 5 years ago
This seems to support git-like subcommands. Very, very nice: something mostly missing from other option parsers.<p>Now does it generate the synopsis part of a man page automatically?
cozzydalmost 5 years ago
This looks cool but c++17 is required (as far as I can tell, since it requires std::optional), so it&#x27;s difficult to use for many things until all my colleagues (and their clusters) upgrade their compilers.
评论 #24184838 未加载
评论 #24183964 未加载
评论 #24183883 未加载
评论 #24183573 未加载
评论 #24183587 未加载
ho_schialmost 5 years ago
A nice way to declare command line options and arguments. I expected already templates, but some of the generated code looks strange:<p>static VISIT_STRUCT_CONSTEXPR const int max_visitable_members = 69; <a href="https:&#x2F;&#x2F;github.com&#x2F;p-ranav&#x2F;structopt&#x2F;blob&#x2F;master&#x2F;single_include&#x2F;structopt&#x2F;structopt.hpp#L270" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;p-ranav&#x2F;structopt&#x2F;blob&#x2F;master&#x2F;single_incl...</a>
评论 #24186428 未加载
chlialmost 5 years ago
I&#x27;ve used <a href="http:&#x2F;&#x2F;docopt.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;docopt.org&#x2F;</a> in the past for a toy project.<p>It&#x27;s an interesting concept where you define the command line &quot;help&quot; syntax and it generates an arguments structure and an associated parser. I&#x27;ve used the C version, I believe the C++ version is better maintained.
评论 #24187853 未加载
Koshkinalmost 5 years ago
By the way, using variadic templates it&#x27;s not hard to write a <i>strictly-typed</i> command-line parser.
agumonkeyalmost 5 years ago
how many problems in computing are parsing problems ?
评论 #24186551 未加载