Skip to content

taybart/args

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Args

Replicating clap in go.

I started learning rust and really liked clap. I am sure this is a derivitave of something else, blah blah. I thought it would be nice for me to use.

Usage

package main

import (
  "fmt"
  "os"

  "github.com/taybart/args"
)


var (
  app = args.App{
    Name:    "My App",
    Version: "v0.0.1",
    Author:  "Tay Bart <taybart@email.com>",
    About:   "Really cool app for accomplishing stuff",
    Args: map[string]*args.Arg{
      "port": {
        Short:   "p",
        Help:    "Port to listen on",
        Default: 8080,
      },
    },
  }
)

func main() {
  if err := run(); err != nil {
    fmt.Println(err)
    os.Exit(1)
  }
}

func run() error {
  // Set up app
  if err := app.Parse(); err != nil {
    return err
  }
  fmt.Println(app.Int("port"))

  // use go struct
  config := struct {
    Port    int    `arg:"port"`
  }{}
  if err = app.Marshal(&config); err != nil {
    return err
  }
  fmt.Println(config.Port)
  return nil
}

Note: if the variable is supposed to be treated as a boolean, Default: false is required

Reserved flags:

-h,-help,--help

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages