Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Library for parsing command line arguments easily. Like golang flag module.

License

NotificationsYou must be signed in to change notification settings

DieTime/c-flags

Repository files navigation

LinuxMacOSWindows MinGWWindows MSVCLicense typeSingle Header

Library for parsing command line arguments easily. Like golangflag module.

👍 Supportssingle header version

Usage

#include<c-flags.h>#include<inttypes.h>#include<stdio.h>intmain(intargc,char*argv[]){if (argc>0)c_flags_set_application_name(argv[0]);c_flags_set_positional_args_description("<file-path>");c_flags_set_description("A program to demonstrate the capabilities of the c-flags library");bool*verbose=c_flag_bool("verbose","v","verbose mode", false);uint64_t*batch=c_flag_uint64("batch-size","bs","declare batch size",32);size_t*offset=c_flag_size_t("offset","off","declare file offset",0);bool*help=c_flag_bool("help","h","show usage", false);c_flags_parse(&argc,&argv, false);if (*help) {c_flags_usage();return0;    }if (argc==0) {printf("ERROR: required file path not specified\n\n");c_flags_usage();return1;    }char*file_path=argv[0];printf("Parsed command line arguments and flags:\n");printf("   verbose:    %s\n",*verbose ?"true" :"false");printf("   batch-size: %"PRIu64"\n",*batch);printf("   offset:     %zu\n",*offset);printf("   file-path:  %s\n",file_path);return0;}
USAGE:   builddir/examples/example [OPTIONS] <file-path>DESCRIPTION:   A program to demonstrate the capabilities of the c-flags libraryOPTIONS:   --verbose, -v       Description: verbose mode       Default: false   --batch-size, -bs       Description: declare batch size       Default: 32   --offset, -off       Description: declare file offset       Default: 0   --help, -h       Description: show usage       Default: true

Install

$ meson builddir&&cd builddir$ meson compile$ sudo meson install

Linking

The library supportspkg-config, which makes linking easier and more convenient.

cmake_minimum_required(VERSION 3.14)project(program)find_package(PkgConfig)pkg_search_module(C_FLAGS REQUIRED c-flags)add_executable(program examples/example.c)target_compile_options(programPUBLIC${C_FLAGS_CFLAGS})target_link_libraries(programPUBLIC${C_FLAGS_LIBRARIES})

License

Copyright (c) 2023 Denis Glazkovglazzk.off@mail.ru

Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.

About

Library for parsing command line arguments easily. Like golang flag module.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp