Skip to content

owlinux1000/clib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clib

Build Status GoDoc MIT License

clib is yet another golang command line parser.

Install

$ go get github.com/owlinux1000/clib

Example

Here is a sample implemented like git add -u .

package main

import (
    "os"
    "fmt"
    "github.com/owlinux1000/clib"
)

func main() {

    app, err := clib.NewApp("mygit", "1.0.0", "A toy git client")
    if err != nil {
        panic(err)
    }
    
    if err := app.AddCommand("add", "a", "Add file contents to the index", 0); err != nil {
        panic(err)
    }
    
    if err := app.AddOption("-u", "update tracked files", 0); err != nil {
        panic(err)
    }
    
    exitStatus, err := app.Parse(os.Args)
    if err != nil {
        panic(err)
    }

    if ok, _ := app.OptionFlag("-h"); ok {
        fmt.Println(app.Usage())
        os.Exit(exitStatus)
    }

    if ok, _ := app.CommandFlag("add"); ok {
        fmt.Println("You executed `mygit add`")
        if ok, _ := app.OptionFlag("-u"); ok {
            fmt.Println("You executed `mygit add -u`")
        }
    }
    
}

The result executed go run is here.

$ mygit

A toy git client

Usage: 
	mygit [option]
	mygit <command>

Options:
	-h		Display this message
	-u		update tracked files
	-v		Print version info and exit

Commands:
	add		Add file contents to the index

About

clib is yet another golang command line parser.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages