SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
CLI11: Command line parsing made simple
Henry Schreiner
April 24, 2017
2/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
History
Origins in GooFit
• Analysis code in GooFit consists of two things:
PDFs, written in advanced CUDA/OpenMP
The model code
• GooFit tries make the model code simple
• But a lot of code was a command line or option parser
• Or (worse) lots of hard-coded values
• Lots of segfaults in examples from option errors
3/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Alternatives
Requirements
• Clean and simple usage
• Plain types, no runtime lookup
• Easy to include
• Standard shell idioms
• Subcommands
• Configuration files
• Extendable and customizable by a toolkit
4/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Alternatives
Boost Program Options
• Classic standard parser
• Big dependency for a library
• Hard to exit cleanly
• Peculiar syntax
• Interesting tidbit: CLI11 started as a wrapper to Boost::PO
A few others
• TCLAP: Header-only, but limited, poor support
• GFlags: Google’s attempt, nice syntax, but too many macros,
no subcommands
5/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
CLI11
CLI11
• Designed to mimic plumbum.cli, but native to C++11
• Expanded to include features from other libs, like Click
• Header only, single header file option
• Only depends on C++11 (no regex required)
• Used stand alone or subclassed
Well tested
• Continuous Integration (CI) on Linux, Mac, and Windows
• GCC 4.7 and 6, Clang 3.5 and Mac, and Visual Studio 2015
• 100% test coverage on CodeCov, almost 200 tests
• Single header file version compiled from online build
• API documentation generated from online build
• Every function, method, and member documented
6/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Command line parsing
./myprog 1 -vz -ffilename --long=2
Example 1
• The 1 is a “positional” option
• The -v is a short flag
• The z is a chained short flag
• The -f is a short option accepting an argument
• filename is the argument
• --long is a long option, followed by space or =
7/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Command line parsing
git checkout -q -- myfile.txt
Example 2
• checkout is a subcommand
• -n is a short flag
• -- is a positional separator
• Everything after that is a positional
8/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Design
CLI::App app {"A discription"};
// Add options (next slide)
try {
app.parse(argc, argv);
} catch (CLI::Error &e) {
return app.exit(e);
}
Basics
• The parser is an instance of a CLI::App
• You set up your options (next slide)
• Parsing is (correctly) done with a try statement
9/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Flags
app.add_flag("-n,--name", output, "Help string");
Flags
• All apps get a default help flag
• Names are given in a comma separated string
A “-” name is a short option
A “--” name is a long option
• SFINAE is used to select behavior, int-like or bool
10/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Options
std::string output = "default";
app.add_option("filename", output, "Help string");
Options
• 6 behaviors: (int, float, string)-like × vector
• Works with TStrings, boost::filesystem, etc.
• Also a version accepting a transformation function
• Optional final true captures default value in help
• A name without “-” is positional
11/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Options
Specialty
• add_set: Pick from a set
• add_complex: A complex number
• add_config: Add a option for config file
Pointer to options
• Adding options returns pointers
• The behavior of the option can be modified
• The option can be counted
12/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Options
TString fname;
app.add_option("-f", fname, "Existing file")
->required()
->check(CLI::ExistingFile);
Normal usage example
• Configuring an option is simple
• Pointer often not needed
13/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Option modifiers
• ->required()
• ->expected(N)
• ->requires(opt, ...)
• ->excludes(opt, ...)
• ->envname(name)
• ->group(name)
• ->ignore_case()
• ->check(CLI::ExistingFile)
• ->check(CLI::ExistingDirectory)
• ->check(CLI::NonexistentPath)
• ->check(CLI::Range(min,max))
14/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Subcommands
auto subcom = app.add_subcommand("pull", "Help str");
Subcommands
• Subcommands are just CLI::App’s
• Same features
• Can chain infinitely
Suggestion
• Use auto& subcom = *app.add_subcom(... to get
reference
15/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Command/Subcommand modifiers
• .ignore_case()
• .fallthrough()
• .require_subcommand()
• .require_subcommand(N)
• .set_callback(function)
• .allow_extras()
• .get_subcommands()
16/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Subcommands
if(subcom->parsed()) ...
for(auto subcom : app.get_subcommands()) ...
subcom->set_callback([&](){...});
Three ways to use subcomands
• Check to see if they were parsed
• Run over list from .get_subcommands()
• Use callbacks to program inline
Correct parse ordering by CLI11
Best method depends on application
17/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Configuration
; Example of INI file, [default] is assumed
value = 1.23
subcom.flag = true
Ini files
• Support for configuration files
• Can read or produce INI
• Mixes with command line
• Subcommands, flags, etc. are all supported.
Environment variables
• Environment variable input can be added
18/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Library integration
Library integration
• Supports customization for the main App
• Several hooks provided
Example integration: GooFit::Application
• Adds custom options for info and GPU control
• Adds MPI support setup/teardown
• TApplication style constructor/run
• Color support through Rang
19/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
PiPiPi0 Example
[root@8566ea534714 pipipi0DPFit]# ./pipipi0DPFit -h
pipipi0 Dalitz fit example
Usage: ./pipipi0DPFit [OPTIONS] [SUBCOMMAND]
GooFit:
--goofit-details Output system and threading details
Options:
-h,--help Print this help message and exit
--config STRING=config.ini An ini file with command line options in it
Subcommands:
toy Toy MC Performance evaluation
truth Truth Monte Carlo fit
sigma Run sigma fit
efficiency Run efficiency fit
canonical Run the canonical fit
background_dalitz Run the background Dalitz fit
background_sigma Run background sigma fit
background_histograms Write background histograms
run_gen_mc Run generated Monte Carlo fit
make_time_plots Make time plots
20/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
[root@8566ea534714 pipipi0DPFit]# ./pipipi0DPFit canonical -h
Run the canonical fit
Usage: ./pipipi0DPFit canonical [OPTIONS] data
Positionals:
data STRING Data to use
Options:
-h,--help Print this help message and exit
-d,--data STRING Data to use
--luckyFrac FLOAT=0.5
--mesonRad FLOAT=1.5
--normBins INT=240
--blindSeed INT=4
--mdslices INT=1
--offset FLOAT=0 Offest in GeV
--upper_window INT=2
--lower_window INT=-2
--upper_delta_window FLOAT=2
--lower_delta_window FLOAT=-2
--upperTime FLOAT=3
--lowerTime FLOAT=-2
--maxSigma FLOAT=0.8
--polyEff UINT=0
--m23Slices INT=6
--bkgRandSeed INT=-1
--drop-rho_1450
--drop-rho_1700
--drop-f0_600
--histSigma
--makePlots
--mkg2Model STRING in {histogram,parameter,sideband}=sideband
21/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Status
Nearing 1.0 release
• Current version 0.9 was released yesterday
• API stable for last several versions
• Final tasks:
Evaluate user feedback
Evaluate compatibility with ROOT 6 or 7
• GooFit 2.0 release will be proceeded by CLI11 1.0
22/22Henry Schreiner
CLI11: Command line parsing made simple
April 24, 2017
Try it out!
Three easy ways to try it
• Download CLI11.hpp from the latest release
• Get the git repository
• Use CLIUtils CMake AddCLI.cmake to automatically download
Look at FindROOT.cmake and other helpers
Get involved
• Open an Issue or a Pull Request
• Chat on Gitter

Contenu connexe

Plus de Henry Schreiner

HOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex ReconstructionHOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex Reconstruction
Henry Schreiner
 

Plus de Henry Schreiner (20)

PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packagingPyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
boost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meetingboost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meeting
 
Digital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingDigital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meeting
 
CMake best practices
CMake best practicesCMake best practices
CMake best practices
 
Pybind11 - SciPy 2021
Pybind11 - SciPy 2021Pybind11 - SciPy 2021
Pybind11 - SciPy 2021
 
RDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and PandasRDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and Pandas
 
HOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex ReconstructionHOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex Reconstruction
 
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutesHOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
 
ACAT 2019: A hybrid deep learning approach to vertexing
ACAT 2019: A hybrid deep learning approach to vertexingACAT 2019: A hybrid deep learning approach to vertexing
ACAT 2019: A hybrid deep learning approach to vertexing
 
2019 CtD: A hybrid deep learning approach to vertexing
2019 CtD: A hybrid deep learning approach to vertexing2019 CtD: A hybrid deep learning approach to vertexing
2019 CtD: A hybrid deep learning approach to vertexing
 
2019 IRIS-HEP AS workshop: Boost-histogram and hist
2019 IRIS-HEP AS workshop: Boost-histogram and hist2019 IRIS-HEP AS workshop: Boost-histogram and hist
2019 IRIS-HEP AS workshop: Boost-histogram and hist
 
IRIS-HEP: Boost-histogram and Hist
IRIS-HEP: Boost-histogram and HistIRIS-HEP: Boost-histogram and Hist
IRIS-HEP: Boost-histogram and Hist
 
2019 IRIS-HEP AS workshop: Particles and decays
2019 IRIS-HEP AS workshop: Particles and decays2019 IRIS-HEP AS workshop: Particles and decays
2019 IRIS-HEP AS workshop: Particles and decays
 
IRIS-HEP Retreat: Boost-Histogram Roadmap
IRIS-HEP Retreat: Boost-Histogram RoadmapIRIS-HEP Retreat: Boost-Histogram Roadmap
IRIS-HEP Retreat: Boost-Histogram Roadmap
 
PyHEP 2019: Python 3.8
PyHEP 2019: Python 3.8PyHEP 2019: Python 3.8
PyHEP 2019: Python 3.8
 
PyHEP 2019: Python Histogramming Packages
PyHEP 2019: Python Histogramming PackagesPyHEP 2019: Python Histogramming Packages
PyHEP 2019: Python Histogramming Packages
 
2019 IML workshop: A hybrid deep learning approach to vertexing
2019 IML workshop: A hybrid deep learning approach to vertexing2019 IML workshop: A hybrid deep learning approach to vertexing
2019 IML workshop: A hybrid deep learning approach to vertexing
 
CHEP 2019: Recent developments in histogram libraries
CHEP 2019: Recent developments in histogram librariesCHEP 2019: Recent developments in histogram libraries
CHEP 2019: Recent developments in histogram libraries
 
DIANA: Recent developments in GooFit
DIANA: Recent developments in GooFitDIANA: Recent developments in GooFit
DIANA: Recent developments in GooFit
 

Dernier

Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
Areesha Ahmad
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Sérgio Sacani
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
NazaninKarimi6
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
seri bangash
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
PirithiRaju
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformation
Areesha Ahmad
 

Dernier (20)

COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
 
Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit flypumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
 
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learning
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformation
 
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICESAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
 

DIANA: CLI11: Command line parsing made simple

  • 1. CLI11: Command line parsing made simple Henry Schreiner April 24, 2017
  • 2. 2/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 History Origins in GooFit • Analysis code in GooFit consists of two things: PDFs, written in advanced CUDA/OpenMP The model code • GooFit tries make the model code simple • But a lot of code was a command line or option parser • Or (worse) lots of hard-coded values • Lots of segfaults in examples from option errors
  • 3. 3/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Alternatives Requirements • Clean and simple usage • Plain types, no runtime lookup • Easy to include • Standard shell idioms • Subcommands • Configuration files • Extendable and customizable by a toolkit
  • 4. 4/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Alternatives Boost Program Options • Classic standard parser • Big dependency for a library • Hard to exit cleanly • Peculiar syntax • Interesting tidbit: CLI11 started as a wrapper to Boost::PO A few others • TCLAP: Header-only, but limited, poor support • GFlags: Google’s attempt, nice syntax, but too many macros, no subcommands
  • 5. 5/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 CLI11 CLI11 • Designed to mimic plumbum.cli, but native to C++11 • Expanded to include features from other libs, like Click • Header only, single header file option • Only depends on C++11 (no regex required) • Used stand alone or subclassed Well tested • Continuous Integration (CI) on Linux, Mac, and Windows • GCC 4.7 and 6, Clang 3.5 and Mac, and Visual Studio 2015 • 100% test coverage on CodeCov, almost 200 tests • Single header file version compiled from online build • API documentation generated from online build • Every function, method, and member documented
  • 6. 6/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Command line parsing ./myprog 1 -vz -ffilename --long=2 Example 1 • The 1 is a “positional” option • The -v is a short flag • The z is a chained short flag • The -f is a short option accepting an argument • filename is the argument • --long is a long option, followed by space or =
  • 7. 7/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Command line parsing git checkout -q -- myfile.txt Example 2 • checkout is a subcommand • -n is a short flag • -- is a positional separator • Everything after that is a positional
  • 8. 8/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Design CLI::App app {"A discription"}; // Add options (next slide) try { app.parse(argc, argv); } catch (CLI::Error &e) { return app.exit(e); } Basics • The parser is an instance of a CLI::App • You set up your options (next slide) • Parsing is (correctly) done with a try statement
  • 9. 9/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Flags app.add_flag("-n,--name", output, "Help string"); Flags • All apps get a default help flag • Names are given in a comma separated string A “-” name is a short option A “--” name is a long option • SFINAE is used to select behavior, int-like or bool
  • 10. 10/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Options std::string output = "default"; app.add_option("filename", output, "Help string"); Options • 6 behaviors: (int, float, string)-like × vector • Works with TStrings, boost::filesystem, etc. • Also a version accepting a transformation function • Optional final true captures default value in help • A name without “-” is positional
  • 11. 11/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Options Specialty • add_set: Pick from a set • add_complex: A complex number • add_config: Add a option for config file Pointer to options • Adding options returns pointers • The behavior of the option can be modified • The option can be counted
  • 12. 12/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Options TString fname; app.add_option("-f", fname, "Existing file") ->required() ->check(CLI::ExistingFile); Normal usage example • Configuring an option is simple • Pointer often not needed
  • 13. 13/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Option modifiers • ->required() • ->expected(N) • ->requires(opt, ...) • ->excludes(opt, ...) • ->envname(name) • ->group(name) • ->ignore_case() • ->check(CLI::ExistingFile) • ->check(CLI::ExistingDirectory) • ->check(CLI::NonexistentPath) • ->check(CLI::Range(min,max))
  • 14. 14/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Subcommands auto subcom = app.add_subcommand("pull", "Help str"); Subcommands • Subcommands are just CLI::App’s • Same features • Can chain infinitely Suggestion • Use auto& subcom = *app.add_subcom(... to get reference
  • 15. 15/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Command/Subcommand modifiers • .ignore_case() • .fallthrough() • .require_subcommand() • .require_subcommand(N) • .set_callback(function) • .allow_extras() • .get_subcommands()
  • 16. 16/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Subcommands if(subcom->parsed()) ... for(auto subcom : app.get_subcommands()) ... subcom->set_callback([&](){...}); Three ways to use subcomands • Check to see if they were parsed • Run over list from .get_subcommands() • Use callbacks to program inline Correct parse ordering by CLI11 Best method depends on application
  • 17. 17/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Configuration ; Example of INI file, [default] is assumed value = 1.23 subcom.flag = true Ini files • Support for configuration files • Can read or produce INI • Mixes with command line • Subcommands, flags, etc. are all supported. Environment variables • Environment variable input can be added
  • 18. 18/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Library integration Library integration • Supports customization for the main App • Several hooks provided Example integration: GooFit::Application • Adds custom options for info and GPU control • Adds MPI support setup/teardown • TApplication style constructor/run • Color support through Rang
  • 19. 19/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 PiPiPi0 Example [root@8566ea534714 pipipi0DPFit]# ./pipipi0DPFit -h pipipi0 Dalitz fit example Usage: ./pipipi0DPFit [OPTIONS] [SUBCOMMAND] GooFit: --goofit-details Output system and threading details Options: -h,--help Print this help message and exit --config STRING=config.ini An ini file with command line options in it Subcommands: toy Toy MC Performance evaluation truth Truth Monte Carlo fit sigma Run sigma fit efficiency Run efficiency fit canonical Run the canonical fit background_dalitz Run the background Dalitz fit background_sigma Run background sigma fit background_histograms Write background histograms run_gen_mc Run generated Monte Carlo fit make_time_plots Make time plots
  • 20. 20/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 [root@8566ea534714 pipipi0DPFit]# ./pipipi0DPFit canonical -h Run the canonical fit Usage: ./pipipi0DPFit canonical [OPTIONS] data Positionals: data STRING Data to use Options: -h,--help Print this help message and exit -d,--data STRING Data to use --luckyFrac FLOAT=0.5 --mesonRad FLOAT=1.5 --normBins INT=240 --blindSeed INT=4 --mdslices INT=1 --offset FLOAT=0 Offest in GeV --upper_window INT=2 --lower_window INT=-2 --upper_delta_window FLOAT=2 --lower_delta_window FLOAT=-2 --upperTime FLOAT=3 --lowerTime FLOAT=-2 --maxSigma FLOAT=0.8 --polyEff UINT=0 --m23Slices INT=6 --bkgRandSeed INT=-1 --drop-rho_1450 --drop-rho_1700 --drop-f0_600 --histSigma --makePlots --mkg2Model STRING in {histogram,parameter,sideband}=sideband
  • 21. 21/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Status Nearing 1.0 release • Current version 0.9 was released yesterday • API stable for last several versions • Final tasks: Evaluate user feedback Evaluate compatibility with ROOT 6 or 7 • GooFit 2.0 release will be proceeded by CLI11 1.0
  • 22. 22/22Henry Schreiner CLI11: Command line parsing made simple April 24, 2017 Try it out! Three easy ways to try it • Download CLI11.hpp from the latest release • Get the git repository • Use CLIUtils CMake AddCLI.cmake to automatically download Look at FindROOT.cmake and other helpers Get involved • Open an Issue or a Pull Request • Chat on Gitter