GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - prnvbn/pflags: Drop-in replacement for Odin's core:flags, implementing POSIX/GNU-style -f/--flags

BranchesTags
Open more actions menu

Latest commit

 

History

18 Commits
18 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
test
test
 
 
.gitignore
.gitignore
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
constants.odin
constants.odin
 
 
doc.odin
doc.odin
 
 
errors.odin
errors.odin
 
 
internal_assignment.odin
internal_assignment.odin
 
 
internal_parsing.odin
internal_parsing.odin
 
 
internal_rtti.odin
internal_rtti.odin
 
 
internal_validation.odin
internal_validation.odin
 
 
odinfmt.json
odinfmt.json
 
 
ols.json
ols.json
 
 
parsing.odin
parsing.odin
 
 
rtti.odin
rtti.odin
 
 
usage.odin
usage.odin
 
 
util.odin
util.odin
 
 
validation.odin
validation.odin
 
 
version.txt
version.txt
 
 

Repository files navigation

pflags

pflags is a drop-in replacement for Odin's core:flags, with support for conventional short (-f) and long (--flag) options.

Comparison against core:flags

pflags has exactly the same public API as Odin's core:flags. Only the .Unix parsing style differs:

  • Long flags use --flag strictly; -flag is never interpreted as a long flag.
  • Short flags can be declared with args:"short=f" and used as -f.
  • Short-option values may be attached (-oapp.out) or separate (-o app.out).
  • Boolean short flags can be bundled, so -abc is the same as -a -b -c.

Installation

Clone the library into your project's lib directory:

git clone --branch v0.1.0 --depth 1 \
  https://github.com/prnvbn/pflags.git lib/pflags

to add it as a submodule:

git submodule add https://github.com/prnvbn/pflags.git lib/pflags
git -C lib/pflags checkout v0.1.0

Usage

package main

import "core:fmt"
import "core:os"
import "lib:pflags"

Options :: struct {
	name:    string `args:"short=n" usage:"Name to greet."`,
	verbose: bool   `args:"short=v" usage:"Use a more enthusiastic greeting."`,
}

main :: proc() {
	options := Options{name = "world"}
	pflags.parse_or_exit(&options, os.args, .Unix)

	if options.verbose {
		fmt.printfln("Hello, %s!!!", options.name)
	} else {
		fmt.printfln("Hello, %s!", options.name)
	}
}

Map the lib collection when running or building your program:

odin run . -collection:lib=./lib -- --name Odin -v

Examples

See the examples directory for runnable programs using pflags.

Upstream

I am hoping this change is accepted into core:flags. This PR is proposing the same behaviour in the core pkg: odin-lang/Odin#7001

About

Drop-in replacement for Odin's core:flags, implementing POSIX/GNU-style -f/--flags

Topics

flagsodin-lang

Resources

Readme
Activity

Stars

6 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.