Skip to content

Latest commit

 

History

History
66 lines (52 loc) · 1.17 KB

README.md

File metadata and controls

66 lines (52 loc) · 1.17 KB

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 <[email protected]>",
    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