SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
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

Mais conteúdo relacionado

Mais de Henry Schreiner

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 packagingHenry Schreiner
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsHenry Schreiner
 
boost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meetingboost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meetingHenry Schreiner
 
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 meetingHenry Schreiner
 
RDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and PandasRDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and PandasHenry 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 ReconstructionHenry Schreiner
 
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 minutesHenry Schreiner
 
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 vertexingHenry Schreiner
 
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 vertexingHenry Schreiner
 
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 histHenry Schreiner
 
IRIS-HEP: Boost-histogram and Hist
IRIS-HEP: Boost-histogram and HistIRIS-HEP: Boost-histogram and Hist
IRIS-HEP: Boost-histogram and HistHenry Schreiner
 
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 decaysHenry Schreiner
 
IRIS-HEP Retreat: Boost-Histogram Roadmap
IRIS-HEP Retreat: Boost-Histogram RoadmapIRIS-HEP Retreat: Boost-Histogram Roadmap
IRIS-HEP Retreat: Boost-Histogram RoadmapHenry Schreiner
 
PyHEP 2019: Python Histogramming Packages
PyHEP 2019: Python Histogramming PackagesPyHEP 2019: Python Histogramming Packages
PyHEP 2019: Python Histogramming PackagesHenry Schreiner
 
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 vertexingHenry Schreiner
 
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 librariesHenry Schreiner
 
DIANA: Recent developments in GooFit
DIANA: Recent developments in GooFitDIANA: Recent developments in GooFit
DIANA: Recent developments in GooFitHenry Schreiner
 

Mais 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
 

Último

Unit5-Cloud.pptx for lpu course cse121 o
Unit5-Cloud.pptx for lpu course cse121 oUnit5-Cloud.pptx for lpu course cse121 o
Unit5-Cloud.pptx for lpu course cse121 oManavSingh202607
 
Introduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptxIntroduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptxBhagirath Gogikar
 
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.pdfPirithiRaju
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformationAreesha Ahmad
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Silpa
 
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🍑Damini Dixit
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptxAlMamun560346
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .Poonam Aher Patil
 
IDENTIFICATION OF THE LIVING- forensic medicine
IDENTIFICATION OF THE LIVING- forensic medicineIDENTIFICATION OF THE LIVING- forensic medicine
IDENTIFICATION OF THE LIVING- forensic medicinesherlingomez2
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryAlex Henderson
 
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLKochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLkantirani197
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Servicemonikaservice1
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxRizalinePalanog2
 
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.Nitya salvi
 
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)Joonhun Lee
 
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...Mohammad Khajehpour
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPirithiRaju
 

Último (20)

Unit5-Cloud.pptx for lpu course cse121 o
Unit5-Cloud.pptx for lpu course cse121 oUnit5-Cloud.pptx for lpu course cse121 o
Unit5-Cloud.pptx for lpu course cse121 o
 
Introduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptxIntroduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptx
 
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
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformation
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
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🍑
 
Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .
 
IDENTIFICATION OF THE LIVING- forensic medicine
IDENTIFICATION OF THE LIVING- forensic medicineIDENTIFICATION OF THE LIVING- forensic medicine
IDENTIFICATION OF THE LIVING- forensic medicine
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLKochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
 
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
 
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
 

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