Skip to content

mcinglis/libargs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libargs provides functions for parsing arguments according to a declarative specification:

ArgsError err = { .type = ArgsError_NONE };
argparse( argc, argv, &err, ( ArgSpec ){
    .positionals = ARRAY_ARGPOSITIONAL(
        { .name        = "system-id",
          .destination = &system_id
        },
        { .name        = "api-key",
          .destination = &api_key
        }
    ),
    .flags = ARRAY_ARGFLAG(
        { .name        = "--version",
          .destination = &got_version_flag
        },
        { .names       = ARRAY_STR( "--help", "-h" ),
          .destination = &got_help_flag
        }
    ),
    .options = ARRAY_ARGOPTION(
        { .name        = "--widget-file",
          .destination = &widget_file
        },
        { .names       = ARRAY_STR( "--times", "-t" ),
          .destination = &times,
          .num_args    = { .min = ArgsNum_NONE, .max = ArgsNum_INFINITE },
          .parser      = time__arg_parse
        }
    )
} );
if ( err.type != ArgsError_NONE ) {
    // handle error
}
// use values set from `argparse()`...

See examples/demo.c for a full example.

Releases

I'll tag the releases according to semantic versioning. All the macros preceded by // @public are considered public: they'll only change between major versions. The other macros could change any time. Non-preprocessor identifiers defined in header files are always considered public. New identifiers prefixed with arg (any case) will not warrant a major version bump.

Every version tag will be signed with my GPG key (fingerprint: 0xD020F814).

Dependencies

Package.json specifies the dependencies of Libargs: where to get them, and what version to use. I've developed a tool called Puck that will parse such a Package.json, download the specified repositories, check out the specified version, and, if the dependency has its own Package.json, repeat that process for its dependencies. With puck on your PATH, in the directory of Libargs:

$ puck update
$ puck execute build

There's nothing magic to what Puck does, so if you would prefer, you can set up the dependencies manually. You just need to have the dependencies in the deps directory within the Libargs directory, and have them built (if necessary) before building Libargs.

There is no build command specified for Libargs, because you should manage the building of Libargs' sources in your own project. The dependencies rely on generated source files, and you would want to have that process integrated with the rest of your project, avoiding multiple libraries trying to generate the same file differently. Nonetheless, there is a Makefile provided that will build the object files and example programs.

Collaboration

Libargs is available at Bitbucket and GitHub.

Questions, discussion, bug reports and feature requests are welcome at the GitHub issue tracker, or via emails.

To contribute changes, you're welcome to email me patches as per git format-patch, or to send me a pull request on any of the aforementioned sites. You're also welcome to just send me a link to your remote repository, and I'll merge stuff from that as I want to.

To accept notable contributions, I'll require you to assign your copyright to me. In your email/pull request and commit messages, please insert: "I hereby irrevocably transfer to Malcolm Inglis (http:https://minglis.id.au) all copyrights, title, and interest, throughout the world, in these contributions to Libargs". If you can, please sign the email or pull request, ensuring your GPG key is publicly available.

License

Copyright 2015 Malcolm Inglis http:https://minglis.id.au

Libargs is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Libargs is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Libargs If not, see https://gnu.org/licenses/.

Contact me for proprietary licensing options.

Why AGPL?

I believe that nonfree software is harmful, and I don't want to contribute to its development at all. I believe that a free society must necessarily operate on free software. I want to encourage the development of free software, and discourage the development of nonfree software.

The GPL was designed to ensure that the software stays free software; "to ensure that every user has freedom". The GPL's protections may have sufficed in 1990, but they don't in 2015. The GPL doesn't consider users of a web service to be users of the software implementing that server. Thankfully, the AGPL does.

The AGPL ensures that if Libargs is used to implement a web service, then the entire source code of that web service must be free software. This way, I'm not contributing to nonfree software, whether it's executed locally or provided over a network.

About

Argument parsing library for C.

Resources

Stars

Watchers

Forks

Packages

No packages published