GithubHelp home page GithubHelp logo

pirmd / clapp Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 226 KB

`clapp` provides simple means to build a command-line application, featuring several levels of sub-commands, flags and args parsing, help and manpage generation, config file parser and build version integration with git.

License: BSD 2-Clause "Simplified" License

Go 96.89% Shell 3.11%
command-line

clapp's Introduction

CLAPP

GoDoc  Go Report Card 

clapp provides simple means to build a command-line application, featuring several levels of sub-commands, flags and args parsing, help and manpage generation, config file parser and build version integration with git.

clapp is probably not as features complete as other command-line application builders existing in the wild but tries to stay simple.

EXAMPLE

package main

import (
    "fmt"
    "encoding/json"

    "github.com/pirmd/clapp"
)

type config struct {
    Species   string
}

func main() {
    cfg := &config{
        Species: "Tamarin", //Species defaults to Tamarin if not altered by a command flag
    }

    cmd := &clapp.Command{
        Name:        "monkey",
        Usage:       "A command-line monkey simulator.",
        Description: "monkey is a command-line companion that provides you with endless untertaining interactions.",

        Config: &clapp.Config{
            Unmarshaller: json.Unmarshal,
            Files:        clapp.DefaultConfigFiles("config.yaml"),
            Var:          cfg,
        },

        ShowHelp:    clapp.ShowUsage,
        ShowVersion: clapp.ShowVersion,
     }

     cmd.Flags = clapp.Flags{
         {
            Name:  "species",
            Usage: "Monkey's species to simulate.",
            Var:   &cfg.Species,
         },
     }

     var fruit string
     cmd.SubCommands.Add(&clapp.Command{
        Name:  "eat",
        Usage: "Give something to eat to your monkey. Be aware that lelectronic monkey eats only bananas.",
        Args: clapp.Args{
            {
                Name:  "fruit",
                Usage: "Fruit to eat.",
                Var:   &fruit,
            },
        },
        Execute: func() error {
            if fruit != "banana" {
                return fmt.Errorf("%s only eats bananas", cfg.Species)
            }

            fmt.Printf("%s loves eating %s", cfg.Species, fruit)
            return nil
        },
    })

    cmd.MustRun([]string{"eat", "banana"}) //usually cmd.MustRun(os.Args[1:])
    //Output: Tamarin loves eating banana
}

A slightly more complete example with documentation generation can be found in gostore.

INSTALLATION

Everything should work fine using go standard commands (build, get, install...).

USAGE

Running go doc github.com/pirmd/clapp should give you helpful guidelines on available features.

CONTRIBUTION

If you feel like to contribute, just follow github guidelines on forking then send a pull request

clapp's People

Contributors

pirmd avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.