Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/jpvetterli/args

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/jpvetterli/args

  • v1.0.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

args

Define and parse command line arguments.

GoDoc

The package keeps simple things simple and makes complicated things possible. For example, this is a simple program argument:

  help

and this is something more complicated:

  include=[
    /home/u649/.db.conf
    extractor=[\s*"(\S+)"\s*:\s*"(\S+)"\s*]
    keys=[user=usr password=$PASS]
  ]

With package args, both examples are handled with minimal application logic.

Parameters are defined in one-liners, with synonyms, documentation, and other configuration details. Values are directly taken into simple variables, arrays or slices. Arbitrary types are easily supported like in this example:

a := args.NewParser()
var target time.Time

scanner := func(value string, target interface{}) error {
    if s, ok := target.(*time.Time); ok {
        if t, err := time.Parse("2006-01-02 15:04:05", value); err == nil {
            *s = t
        } else {
            return err
        }
        return nil
    }
    return fmt.Errorf(`time scanner error: "%s", *time.Time target required, not %T`, value, target)
}

// define parameter "time", use custom scanner
a.Def("time", &target).Scan(scanner).Aka("datetime").Doc(`specify time in the format "yyyy-mm-dd hh:mm:ss"`)

// parse an input
a.Parse("time=[2015-06-30 15:32:00]")

// voilà! the value is in the variable
fmt.Println(target.String()) // prints: 2015-06-30 15:32:00 +0000 UTC

More information and examples are available from the package documentation.

FAQs

Package last updated on 25 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc