Skip to content

StompRocket/yurt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yurt

https://img.shields.io/travis/StompRocket/yurt.svg?style=for-the-badge https://img.shields.io/badge/godoc-reference-375EB1.svg?style=for-the-badge

A WIP Go CLI library

Docs

Read the docs on godoc, click the shield above, or read them offline with godoc github.com/StompRocket/yurt or godoc . if you've cloned the repository.

Installation

go get github.com/StompRocket/yurt

Usage

This is pretty much the simplest program you can write with yurt. It parses the args and does stuff with them. It's pretty self explanatory but there's more detail in the comments

package main

import (
    "github.com/StompRocket/yurt"
    "fmt"
    "os"
)

func main() {
    // Commands are stored in this
    var p yurt.Parser

    // Args: command string, description string, handler func([]string)
    // empty command is used as default
    p.Command("", "", func(_ []string) {
        // displays a help message showing all available commands
        p.Help()
    })

    // An actual command that actually works and is an actual command
    p.Command("foo", "An example", func(matches []string) {
        fmt.Println("Matches", matches)
    })

    // actually parse the args, and call the appropriate lambda
    p.Run(os.Args)
}

Test

$ go test
╭──────────────╮
│ Hello, World │
╰──────────────╯
╭─────╮
│ Red │
╰─────╯
Called Default
Called foo
Called var foo
PASS

About

A CLI framework for go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages