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 — pflags/README.md at main · prnvbn/pflags

Expand file tree

/

README.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
72 lines (51 loc) · 1.84 KB
/

README.md

Copy path

File metadata and controls

72 lines (51 loc) · 1.84 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

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

You are visitor 01402792 — 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.