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

github.com/pnelson/cli-reflection

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/pnelson/cli-reflection

  • v0.0.0-20140723153255-20ff8688301a
  • Source
  • Go
  • Socket score

Version published
Created
Source

cli

Note: I don't really like this structure any more. I've opted for a more simple, reflection-free structure. See https://github.com/pnelson/cli and consider this package deprecated.

Package cli provides structure for command line applications with sub-commands.

This package uses a touch of reflection magic to dispatch to a method with named arguments. Commands help and version are implemented by default. The usage information is pretty printed in an opinionated format.

The most basic cli application is boring:

app := cli.New("myapp", "0.0.1") app.Run()

Build and run your application:

$ ./myapp Usage: myapp [options] [] help Output this usage information. version Output the application version

Add commands:

type add struct { showExtra *bool example *string number *int }

func (c *add) Flags(flags *flag.FlagSet) { c.showExtra = flags.Bool("show-extra", false, "Print extra arguments.") c.example = flags.String("example", "", "An example string option.") c.number = flags.Int("number", 0, "An example int option.") }

func (c *add) Run(key, username string, extra []string) { fmt.Printf("%s => %s\n", key, username) if *c.showExtra { fmt.Printf(" %v\n", extra) } }

func (c *add) String() string { return "Add record key with username." }

func main() { app := cli.New("myapp", "0.0.1") app.Rule(&add{}, "add", " []") app.Run() }

Try building and running your application again:

$ ./myapp Usage: myapp [options] [] help Output this usage information. version Output the application version. add [options] [] Add record key with username. -example= An example string option. -number= An example int option. -show-extra Print extra arguments.

Copyright (c) 2014 by Philip Nelson. See LICENSE for details.

FAQs

Package last updated on 23 Jul 2014

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