cmd

package
v0.0.0-...-2fa30e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const Description = `` /* 469-byte string literal not displayed */

Variables

View Source
var GetCommand = cli.Command{
	Name:        "get",
	Usage:       "Get the file from GitHub",
	Description: Description,
	Action: func(c *cli.Context) error {
		arg0 := c.Args().Get(0)
		url_part := strings.Split(arg0, "/")
		var url string
		const url_head = "https://raw.githubusercontent.com/"
		L := c.NArg()
		switch n := len(url_part); true {
		case n == 2:
			if L != 2 {
				fmt.Fprint(os.Stderr, "[ghscr][Error] invalid arguments\n")
				os.Exit(1)
			}
			url = url_head + arg0 + "/master/" + c.Args().Get(1)
		case n == 3:
			if L != 2 {
				fmt.Fprint(os.Stderr, "[ghscr][Error] invalid arguments\n")
				os.Exit(1)
			}
			url = url_head + arg0 + "/" + c.Args().Get(1)
		case n > 3:
			url = url_head + arg0
		default:
			fmt.Fprint(os.Stderr, "[ghscr][Error] invalid arguments\n")
			os.Exit(1)
		}

		if c.Bool("O") {
			err := exec.Command("curl", url, "-O").Run()
			if err != nil {
				fmt.Fprintf(os.Stderr, "[ghscr][Error] %s\n", err)
				os.Exit(1)
			}
			os.Exit(0)
		}

		if len(c.String("o")) > 0 {
			err := exec.Command("curl", url, "-o", c.String("o")).Run()
			if err != nil {
				fmt.Fprintf(os.Stderr, "[ghscr][Error] %s\n", err)
				os.Exit(1)
			}
			os.Exit(0)
		}

		out, err := exec.Command("curl", url).Output()
		if err != nil {
			fmt.Fprintf(os.Stderr, "[ghscr][Error] %s\n", err)
			os.Exit(1)
		}
		fmt.Println(string(out))
		return nil
	},
	Flags: []cli.Flag{
		cli.BoolFlag{
			Name:  "O",
			Usage: "curl's -O option",
		},
		cli.StringFlag{
			Name:  "o",
			Value: "",
			Usage: "curl's -o option",
		},
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL