All Projects → ProfOak → Flag2

ProfOak / Flag2

Licence: mit
A more traditional flag library for the go programming language

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Flag2

Command Line Api
Command line parsing, invocation, and rendering of terminal output.
Stars: ✭ 2,418 (+6263.16%)
Mutual labels:  command-line, posix
Saldl
A lightweight well-featured CLI downloader optimized for speed and early preview.
Stars: ✭ 203 (+434.21%)
Mutual labels:  command-line, posix
Cobra
A Commander for modern Go CLI interactions
Stars: ✭ 24,437 (+64207.89%)
Mutual labels:  command-line, posix
Yori
Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
Stars: ✭ 948 (+2394.74%)
Mutual labels:  command-line
Ps Clone
A clone of unix ps program
Stars: ✭ 30 (-21.05%)
Mutual labels:  command-line
Awesome Unix
All the UNIX and UNIX-Like: Linux, BSD, macOS, Illumos, 9front, and more.
Stars: ✭ 973 (+2460.53%)
Mutual labels:  posix
Notify.uno
Get notified when your command is done
Stars: ✭ 38 (+0%)
Mutual labels:  command-line
Goat
POSIX-compliant shell movement boosting hack for real ninjas (aka `cd x` and `cd ...`)
Stars: ✭ 27 (-28.95%)
Mutual labels:  posix
Gargantua
The fast website crawler
Stars: ✭ 35 (-7.89%)
Mutual labels:  command-line
Shell Functools
Functional programming tools for the shell
Stars: ✭ 971 (+2455.26%)
Mutual labels:  command-line
Clistats
A command line interface tool to compute statistics from a file or the command line.
Stars: ✭ 33 (-13.16%)
Mutual labels:  command-line
Stack Run
Like cabal run for stack
Stars: ✭ 32 (-15.79%)
Mutual labels:  command-line
Google Images Download
Python Script to download hundreds of images from 'Google Images'. It is a ready-to-run code!
Stars: ✭ 7,815 (+20465.79%)
Mutual labels:  command-line
Tokio File Unix
Asynchronous support for epollable files via Tokio on Unix-like platforms
Stars: ✭ 29 (-23.68%)
Mutual labels:  posix
Mesos Cli
Alternative Apache Mesos CLI
Stars: ✭ 37 (-2.63%)
Mutual labels:  command-line
Todo r
Find all your TODO notes with one command!
Stars: ✭ 28 (-26.32%)
Mutual labels:  command-line
Trash
macOS command line tool to move files to trash
Stars: ✭ 35 (-7.89%)
Mutual labels:  command-line
Jc
CLI tool and python library that converts the output of popular command-line tools and file-types to JSON or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
Stars: ✭ 967 (+2444.74%)
Mutual labels:  command-line
Verticalize
Simple tool to verticalize text delimited files.
Stars: ✭ 32 (-15.79%)
Mutual labels:  command-line
Wonders
🌈 Declarative JavaScript framework to build command-line applications.
Stars: ✭ 34 (-10.53%)
Mutual labels:  command-line

Flag2

A more traditional flag library for the go programming language

What?

======= A more traditional flag library for the Go programming language. I also have a long history with Python, so the implimentation code looks similar to Python's argparse class.

Why?

I did not like how the flag library that comes with Go parses command line flags.

Differences

  • You can define full word flags with the -- prefix. You can define single character flags with the - prefix.

  • Example of a full word flag: --help

  • Example of a single character flag: -h

  • Single character strings can be grouped, but only for boolean types: -abcd is essentially -a, -b, -c, -d

    • This only works for boolean type flags
  • -- denotes the end of the command line flag options

    • Everything to the right of -- will not be counted as flags

Getting started

To install: go get github.com/ProfOak/flag2

package main

import (
    "os"
    "fmt"
    "github.com/ProfOak/flag2"
)

func main() {
    f := flag2.NewFlag()

    // short flag, long flag, description, default argument
    f.AddString("n", "name", "this flag wants a name as input", "billy")
    f.AddBool("b", "bool", "this flag will store true", false)

    // a help flag is added during the parse step
    options, args := f.Parse(os.Args)

    // A usage method is provided, with details about each flag

    // unfortunate side effect of interfaces
    if options["help"] == true {
        f.Usage()
    }

    fmt.Println()
    if options["name"] != nil {
        fmt.Println("The name is:", options["name"])
    }

    fmt.Println()
    fmt.Println("===== FINAL RESULTS =====")
    fmt.Println("Options:", options)
    fmt.Println("Args:", args)
}

The result of running this program:

go run main.go -b -n ProfOak Extra args

--- Bools ---
-b, --bool      this flag will store true
-h, --help      Display this message and exit

--- Strings ---
-n, --name      this flag wants a name as input

Name is: ProfOak

===== FINAL RESULTS =====
Options: map[help:true bool:true name:ProfOak]
Args: [Extra args]

Reference ./test/test.go for a more detailed example.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].