Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Oct 13, 2024
0 parents commit bb558a0
Show file tree
Hide file tree
Showing 10 changed files with 797 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
BasedOnStyle: LLVM
Standard: c++20

IndentWidth: 4
AccessModifierOffset: -2
ColumnLimit: 110

AlignAfterOpenBracket: BlockIndent

AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true

AlignEscapedNewlines: Left

AlignOperands: AlignAfterOperator

AlignTrailingComments: true

AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true

AllowShortBlocksOnASingleLine: Never
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine

BinPackArguments: false
BinPackParameters: false

BitFieldColonSpacing: Both

BreakBeforeBraces: Allman

BreakBeforeBinaryOperators: NonAssignment

BreakConstructorInitializers: BeforeComma
PackConstructorInitializers: CurrentLine

SortIncludes: false
PointerAlignment: Left

PenaltyExcessCharacter: 5
PenaltyBreakAssignment: 10
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# cmkr
/**/CMakeLists.txt linguist-generated
/**/cmkr.cmake linguist-vendored
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cmkr
build*/
cmake-build*/
CMakerLists.txt
CMakeLists.txt.user
62 changes: 62 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# args

Minimal header-only C++11 argument parser library for simple command line tools.

## Usage

Fetch the project in your CMakeLists.txt:

```cmake
include(FetchContent)
FetchContent_Declare(args
GIT_REPOSITORY
"https://github.com/LLVMParty/args"
GIT_TAG
v1.0
)
FetchContent_MakeAvailable(args)
```

Then inherit from `ArgumentParser` and add your flags:

```cpp
#include <cstdio>
#include "args.hpp"

struct Arguments : public ArgumentParser
{
std::string input;
std::string output;
bool parallel = false;

Arguments(int argc, char** argv) : ArgumentParser("Example")
{
addPositional("input", input, "Input file", true);
addString("-output", output, "Output file");
addBool("-parallel", parallel, "Process the input on multiple threads");
parseOrExit(argc, argv);
}
};

int main(int argc, char** argv)
{
Arguments args(argc, argv);
printf("input: '%s'\n", args.input.c_str());
printf("output: '%s'\n", args.output.c_str());
printf("parallel: %s\n", args.parallel ? "yes" : "no");
return EXIT_SUCCESS;
}
```
14 changes: 14 additions & 0 deletions cmake.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "args"

[target.args]
type = "interface"
alias = "args::args"
include-directories = ["include"]
compile-features = ["cxx_std_11"]

[target.example]
type = "executable"
condition = "root"
sources = ["src/example.cpp"]
link-libraries = ["args::args"]
Loading

0 comments on commit bb558a0

Please sign in to comment.