├── .gitignore ├── .travis.yml ├── Gopkg.lock ├── Gopkg.toml ├── LICENSE ├── Makefile ├── README.md ├── a_main-packr.go ├── docker-compose.yml ├── generate.go ├── generate_test.go ├── init.sql ├── install.sh ├── main-packr.go ├── main.go ├── migrate.go ├── sqlfmt └── sqlfmt.go ├── sqltypes └── sqltypes.go ├── tmpl ├── model.html ├── tmpl.go ├── types.go ├── x_helpers.html └── x_helpers_test.html ├── vendor └── github.com │ ├── go-sql-driver │ └── mysql │ │ ├── .github │ │ ├── ISSUE_TEMPLATE.md │ │ └── PULL_REQUEST_TEMPLATE.md │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── AUTHORS │ │ ├── CHANGELOG.md │ │ ├── CONTRIBUTING.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── appengine.go │ │ ├── benchmark_test.go │ │ ├── buffer.go │ │ ├── collations.go │ │ ├── connection.go │ │ ├── connection_test.go │ │ ├── const.go │ │ ├── driver.go │ │ ├── driver_test.go │ │ ├── dsn.go │ │ ├── dsn_test.go │ │ ├── errors.go │ │ ├── errors_test.go │ │ ├── infile.go │ │ ├── packets.go │ │ ├── packets_test.go │ │ ├── result.go │ │ ├── rows.go │ │ ├── statement.go │ │ ├── transaction.go │ │ ├── utils.go │ │ └── utils_test.go │ ├── gobuffalo │ ├── envy │ │ ├── .env │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── envy.go │ │ ├── envy_test.go │ │ └── test_env │ │ │ ├── .env │ │ │ └── .env.prod │ └── packr │ │ ├── .codeclimate.yml │ │ ├── .gitignore │ │ ├── .goreleaser.yml │ │ ├── .travis.yml │ │ ├── LICENSE.txt │ │ ├── README.md │ │ ├── box.go │ │ ├── box_test.go │ │ ├── builder │ │ ├── box.go │ │ ├── builder.go │ │ ├── builder_test.go │ │ ├── clean.go │ │ ├── file.go │ │ ├── pkg.go │ │ ├── tmpl.go │ │ ├── visitor.go │ │ └── visitor_test.go │ │ ├── example │ │ ├── assets │ │ │ ├── app.css │ │ │ └── app.js │ │ ├── bar │ │ │ └── bar.html │ │ ├── baz │ │ │ └── baz.html │ │ ├── example.go │ │ ├── foo │ │ │ ├── bar.go │ │ │ └── foo.go │ │ ├── sf │ │ │ └── foo.html │ │ └── templates │ │ │ └── index.html │ │ ├── file.go │ │ ├── file_info.go │ │ ├── fixtures │ │ ├── goodbye.txt │ │ ├── hello.txt │ │ └── index.html │ │ ├── grifts │ │ └── release.go │ │ ├── http_box_test.go │ │ ├── packr.go │ │ ├── packr │ │ ├── cmd │ │ │ ├── build.go │ │ │ ├── clean.go │ │ │ ├── install.go │ │ │ └── root.go │ │ └── main.go │ │ ├── packr_test.go │ │ ├── physical_file.go │ │ └── virtual_file.go │ ├── inconshreveable │ └── mousetrap │ │ ├── LICENSE │ │ ├── README.md │ │ ├── trap_others.go │ │ ├── trap_windows.go │ │ └── trap_windows_1.4.go │ ├── joho │ └── godotenv │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENCE │ │ ├── README.md │ │ ├── autoload │ │ └── autoload.go │ │ ├── cmd │ │ └── godotenv │ │ │ └── cmd.go │ │ ├── fixtures │ │ ├── equals.env │ │ ├── exported.env │ │ ├── invalid1.env │ │ ├── plain.env │ │ └── quoted.env │ │ ├── godotenv.go │ │ └── godotenv_test.go │ ├── mitchellh │ └── go-homedir │ │ ├── LICENSE │ │ ├── README.md │ │ ├── homedir.go │ │ └── homedir_test.go │ ├── pkg │ └── errors │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── appveyor.yml │ │ ├── bench_test.go │ │ ├── errors.go │ │ ├── errors_test.go │ │ ├── example_test.go │ │ ├── format_test.go │ │ ├── stack.go │ │ └── stack_test.go │ └── spf13 │ ├── cobra │ ├── .gitignore │ ├── .mailmap │ ├── .travis.yml │ ├── LICENSE.txt │ ├── README.md │ ├── args.go │ ├── bash_completions.go │ ├── bash_completions.md │ ├── bash_completions_test.go │ ├── cobra.go │ ├── cobra │ │ ├── README.md │ │ ├── cmd │ │ │ ├── add.go │ │ │ ├── add_test.go │ │ │ ├── golden_test.go │ │ │ ├── helpers.go │ │ │ ├── init.go │ │ │ ├── init_test.go │ │ │ ├── license_agpl.go │ │ │ ├── license_apache_2.go │ │ │ ├── license_bsd_clause_2.go │ │ │ ├── license_bsd_clause_3.go │ │ │ ├── license_gpl_2.go │ │ │ ├── license_gpl_3.go │ │ │ ├── license_lgpl.go │ │ │ ├── license_mit.go │ │ │ ├── licenses.go │ │ │ ├── project.go │ │ │ ├── project_test.go │ │ │ ├── root.go │ │ │ └── testdata │ │ │ │ ├── LICENSE.golden │ │ │ │ ├── main.go.golden │ │ │ │ ├── root.go.golden │ │ │ │ └── test.go.golden │ │ └── main.go │ ├── cobra_test.go │ ├── command.go │ ├── command_notwin.go │ ├── command_test.go │ ├── command_win.go │ ├── doc │ │ ├── cmd_test.go │ │ ├── man_docs.go │ │ ├── man_docs.md │ │ ├── man_docs_test.go │ │ ├── man_examples_test.go │ │ ├── md_docs.go │ │ ├── md_docs.md │ │ ├── md_docs_test.go │ │ ├── rest_docs.go │ │ ├── rest_docs.md │ │ ├── rest_docs_test.go │ │ ├── util.go │ │ ├── yaml_docs.go │ │ ├── yaml_docs.md │ │ └── yaml_docs_test.go │ ├── zsh_completions.go │ └── zsh_completions_test.go │ └── pflag │ ├── .gitignore │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── bool.go │ ├── bool_slice.go │ ├── bool_slice_test.go │ ├── bool_test.go │ ├── count.go │ ├── count_test.go │ ├── duration.go │ ├── example_test.go │ ├── export_test.go │ ├── flag.go │ ├── flag_test.go │ ├── float32.go │ ├── float64.go │ ├── golangflag.go │ ├── golangflag_test.go │ ├── int.go │ ├── int32.go │ ├── int64.go │ ├── int8.go │ ├── int_slice.go │ ├── int_slice_test.go │ ├── ip.go │ ├── ip_slice.go │ ├── ip_slice_test.go │ ├── ip_test.go │ ├── ipmask.go │ ├── ipnet.go │ ├── ipnet_test.go │ ├── string.go │ ├── string_array.go │ ├── string_array_test.go │ ├── string_slice.go │ ├── string_slice_test.go │ ├── uint.go │ ├── uint16.go │ ├── uint32.go │ ├── uint64.go │ ├── uint8.go │ ├── uint_slice.go │ ├── uint_slice_test.go │ └── verify │ ├── all.sh │ ├── gofmt.sh │ └── golint.sh └── visual.svg /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/go 2 | 3 | ### Go ### 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.dll 7 | *.so 8 | *.dylib 9 | 10 | # Test binary, build with `go test -c` 11 | *.test 12 | 13 | # Output of the go coverage tool, specifically when used with LiteIDE 14 | *.out 15 | 16 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 17 | .glide/ 18 | 19 | # End of https://www.gitignore.io/api/go 20 | 21 | .DS_Store 22 | .idea 23 | modelgen 24 | temp -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: go 3 | 4 | go: 5 | - "1.9" 6 | - "1.10" 7 | - master 8 | 9 | services: 10 | - docker 11 | 12 | before_install: 13 | - go get golang.org/x/lint/golint 14 | - go get github.com/gobuffalo/packr/... 15 | 16 | install: 17 | - make test-ci 18 | - make install 19 | - make post 20 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/go-sql-driver/mysql" 6 | packages = ["."] 7 | revision = "a0583e0143b1624142adab07e0e97fe106d99561" 8 | version = "v1.3" 9 | 10 | [[projects]] 11 | name = "github.com/gobuffalo/envy" 12 | packages = ["."] 13 | revision = "e613c80275b86293880eddeb27417c9a7c670ff3" 14 | version = "v1.3.0" 15 | 16 | [[projects]] 17 | name = "github.com/gobuffalo/packr" 18 | packages = ["."] 19 | revision = "64c3dd439b5efc5cd9fb69a8fb209a03cd7c5b86" 20 | version = "v1.10.3" 21 | 22 | [[projects]] 23 | name = "github.com/inconshreveable/mousetrap" 24 | packages = ["."] 25 | revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" 26 | version = "v1.0" 27 | 28 | [[projects]] 29 | name = "github.com/joho/godotenv" 30 | packages = ["."] 31 | revision = "a79fa1e548e2c689c241d10173efd51e5d689d5b" 32 | version = "v1.2.0" 33 | 34 | [[projects]] 35 | branch = "master" 36 | name = "github.com/mitchellh/go-homedir" 37 | packages = ["."] 38 | revision = "b8bc1bf767474819792c23f32d8286a45736f1c6" 39 | 40 | [[projects]] 41 | name = "github.com/pkg/errors" 42 | packages = ["."] 43 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d" 44 | version = "v0.8.0" 45 | 46 | [[projects]] 47 | name = "github.com/spf13/cobra" 48 | packages = ["."] 49 | revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b" 50 | version = "v0.0.1" 51 | 52 | [[projects]] 53 | name = "github.com/spf13/pflag" 54 | packages = ["."] 55 | revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66" 56 | version = "v1.0.0" 57 | 58 | [solve-meta] 59 | analyzer-name = "dep" 60 | analyzer-version = 1 61 | inputs-digest = "b738774e1f55a25c3bc20d02c726869a00555ab0133e468209b45aad6c990b60" 62 | solver-name = "gps-cdcl" 63 | solver-version = 1 64 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | [[constraint]] 2 | name = "github.com/go-sql-driver/mysql" 3 | version = "1.3.0" 4 | 5 | [[constraint]] 6 | name = "github.com/spf13/cobra" 7 | version = "0.0.1" 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | OLD_SHA:=$(shell shasum -a 256 a_main-packr.go | cut -d' ' -f1) 2 | NEW_SHA= $(shell shasum -a 256 a_main-packr.go | cut -d' ' -f1) 3 | 4 | all: test install post 5 | test: 6 | packr 7 | go test -v -count 1 ./... 8 | go build 9 | docker-compose --no-ansi -f docker-compose.yml up -d --force-recreate 10 | sleep 5 11 | ./modelgen -c root:@localhost:3307 -d modelgen_tests -p models generate 12 | golint -set_exit_status generated_models 13 | rm -rf modelgen 14 | rm -rf ./generated_models 15 | test-ci: 16 | go test -v -count 1 ./... 17 | go build 18 | docker-compose --no-ansi -f docker-compose.yml up -d --force-recreate 19 | sleep 30 # annoying, but for ci. 20 | ./modelgen -c root:@localhost:3307 -d modelgen_tests -p models generate 21 | golint -set_exit_status generated_models 22 | rm -rf modelgen 23 | rm -rf ./generated_models 24 | clean: 25 | docker rm -f modelgen-tests 26 | install: 27 | packr && go install 28 | post: 29 | @if [ "$(NEW_SHA)" != "$(OLD_SHA)" ]; then\ 30 | echo "sha comparison failed on a_main-packr.go";\ 31 | exit 1;\ 32 | fi 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Modelgen [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/LUSHDigital/modelgen/master/LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/LUSHDigital/modelgen)](https://goreportcard.com/report/github.com/LUSHDigital/modelgen) [![Build Status](https://travis-ci.org/LUSHDigital/modelgen.svg?branch=master)](https://travis-ci.org/LUSHDigital/modelgen) 2 | 3 | Modelgen generates working database interaction code from reading your MySQL / MariaDB database. 4 | 5 | ## Install: 6 | 7 | ```bash 8 | brew tap lushdigital/tools 9 | brew install modelgen 10 | ``` 11 | 12 | This will install `modelgen` under `/usr/local/bin`. 13 | 14 | If you want to uninstall it, simply delete it, or run `brew uninstall modelgen` 15 | 16 | ## Conventions: 17 | 18 | `modelgen` assumes your database will follow a couple conventions: 19 | 20 | - tables must have a primary key `id` field 21 | - column names must not collide with a valid Go type, ex: string 22 | 23 | The primary `id` doesn't need to auto-increment, though it is recommended. 24 | 25 | ## Ordering: 26 | 27 | In cases where you want the migrations to be generated in a particular order (ex. because of foreign key constraints) 28 | you can control this by simply adding a comment to your `id` field. 29 | 30 | This format must take the following format: 31 | 32 | ``` 33 | # for example a the user table id has the comment: 34 | modelgen:1 35 | 36 | # then the user_post table id has the comment: 37 | modelgen:2 38 | 39 | ``` 40 | 41 | by doing so you ensure that the `user` table always gets migrated before the `user_post` table. 42 | 43 | ## Usage: 44 | 45 | ``` 46 | Usage: 47 | [command] 48 | 49 | Available Commands: 50 | generate Generate models from a database connection 51 | help Help about any command 52 | migrate Generate migration files from a database connection 53 | 54 | Flags: 55 | -c, --connection string user:pass@host:port 56 | -d, --database string name of database 57 | -h, --help help for this command 58 | -o, --output string path to package (default "generated_models") 59 | -p, --package string name of package (default "generated_models") 60 | 61 | Example: 62 | 63 | # Create models 64 | modelgen generate -c root:pass@localhost:3306 -d my-db -o models 65 | 66 | # Create migrations 67 | modelgen migrate -c root:pass@localhost:3306 -d my-db -o migrations 68 | ``` 69 | 70 | ## Visual Aid: 71 | 72 | ![visual.svg](./visual.svg) 73 | 74 | ## Credit: 75 | 76 | Modelgen is built using the following amazing libraries: 77 | 78 | - [github.com/spf13/cobra](https://github.com/spf13/cobra) 79 | - [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) 80 | 81 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | mysql: 5 | container_name: modelgen-tests 6 | image: mysql:5.7 7 | volumes: 8 | - ./init.sql:/docker-entrypoint-initdb.d/init.sql 9 | environment: 10 | MYSQL_ALLOW_EMPTY_PASSWORD: "yes" 11 | restart: always 12 | ports: 13 | - "3307:3306" -------------------------------------------------------------------------------- /generate_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func TestGetOrderFromComment(t *testing.T) { 6 | type args struct { 7 | comment string 8 | } 9 | tests := []struct { 10 | name string 11 | args args 12 | wantOrder int 13 | }{ 14 | { 15 | name: "valid comment", 16 | args: args{ 17 | comment: "modelgen:1", 18 | }, 19 | wantOrder: 1, 20 | }, 21 | { 22 | name: "invalid comment", 23 | args: args{ 24 | comment: "modelgen:2:something else", 25 | }, 26 | wantOrder: 0, 27 | }, 28 | } 29 | for _, tt := range tests { 30 | t.Run(tt.name, func(t *testing.T) { 31 | if gotOrder := GetOrderFromComment(tt.args.comment); gotOrder != tt.wantOrder { 32 | t.Errorf("GetOrderFromComment() = %v, want %v", gotOrder, tt.wantOrder) 33 | } 34 | }) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /init.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE `modelgen_tests`; 2 | 3 | USE `modelgen_tests`; 4 | 5 | -- order is a builtin, tests should pass despite this 6 | DROP TABLE IF EXISTS `order`; 7 | 8 | -- only one field should not break despite the special cases. 9 | CREATE TABLE `order` ( 10 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 11 | PRIMARY KEY (`id`) 12 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 13 | 14 | DROP TABLE IF EXISTS `common_cases`; 15 | 16 | CREATE TABLE `common_cases` ( 17 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 18 | `not_null_string` varchar(255) NOT NULL DEFAULT '', 19 | `not_null_int` int(11) NOT NULL, 20 | `null_string` int(11) DEFAULT NULL, 21 | `null_int` int(11) DEFAULT NULL, 22 | `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 23 | `updated_at` TIMESTAMP NULL DEFAULT NULL, 24 | PRIMARY KEY (`id`) 25 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 26 | 27 | DROP TABLE IF EXISTS `complex_cases`; 28 | 29 | CREATE TABLE `complex_cases` ( 30 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 31 | `raw_json` json NOT NULL, 32 | `size_enum` enum('X-SMALL','SMALL','MEDIUM','LARGE','X-LARGE') DEFAULT NULL, 33 | `updated_at` TIMESTAMP NULL DEFAULT NULL, 34 | PRIMARY KEY (`id`) 35 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 36 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # base directory in which we will extract the files 4 | base="src/github.com/LUSHDigital/modelgen" 5 | 6 | # get the latest tarball url from github's api 7 | url=$(curl -s https://api.github.com/repos/LUSHDigital/modelgen/releases/latest \ 8 | | grep "tarball_url" \ 9 | | cut -d : -f 2,3 \ 10 | | tr -d \"\,\ ) 11 | 12 | # get the tagged version 13 | version=$(curl -s https://api.github.com/repos/LUSHDigital/modelgen/releases/latest \ 14 | | grep "tag_name" \ 15 | | cut -d : -f 2,3 \ 16 | | tr -d \"\,\ ) 17 | 18 | # download the tarball 19 | curl -s -L ${url} --output release.tar.gz 20 | 21 | # set the gopath 22 | export GOPATH=$(pwd) 23 | export PATH="$GOPATH/bin:$PATH" 24 | 25 | # create the base folder 26 | mkdir -p ${base} 27 | 28 | # extract everything into it 29 | tar -xvzf release.tar.gz -C ${base} --strip-components=1 30 | 31 | # move into it 32 | cd ${base} 33 | 34 | # build 35 | go build -ldflags "-X main.version=$version" -o /usr/local/bin/modelgen 36 | go build -ldflags "-X main.version=$version" -o /usr/local/bin/modelgen 37 | 38 | # move back to the root 39 | cd - 40 | 41 | # cleanup the files 42 | rm release.tar.gz 43 | rm -rf src 44 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "database/sql" 5 | "errors" 6 | "fmt" 7 | "log" 8 | "strings" 9 | 10 | "github.com/gobuffalo/packr" 11 | 12 | "github.com/spf13/cobra" 13 | 14 | _ "github.com/go-sql-driver/mysql" 15 | ) 16 | 17 | var ( 18 | output *string 19 | dbName *string 20 | pkgName *string 21 | conn *string 22 | database *sql.DB 23 | version string 24 | box packr.Box 25 | ) 26 | 27 | func init() { 28 | log.SetFlags(log.LstdFlags | log.Lshortfile) 29 | } 30 | 31 | func main() { 32 | box = packr.NewBox("./tmpl") 33 | 34 | rootCmd := &cobra.Command{} 35 | 36 | pkgName = rootCmd.PersistentFlags().StringP("package", "p", "generated_models", "name of package") 37 | output = rootCmd.PersistentFlags().StringP("output", "o", "generated_models", "path to package") 38 | dbName = rootCmd.PersistentFlags().StringP("database", "d", "", "name of database") 39 | conn = rootCmd.PersistentFlags().StringP("connection", "c", "", "user:pass@host:port") 40 | 41 | generateCmd := &cobra.Command{ 42 | Use: "generate", 43 | Run: generate, 44 | Short: "Generate models from a database connection", 45 | } 46 | 47 | migrateCmd := &cobra.Command{ 48 | Use: "migrate", 49 | Run: migrate, 50 | Short: "Generate migration files from a database connection", 51 | } 52 | 53 | versionCmd := &cobra.Command{ 54 | Use: "version", 55 | Run: func(cmd *cobra.Command, args []string) { 56 | fmt.Println(version) 57 | }, 58 | Short: "Returns the current version name", 59 | } 60 | 61 | rootCmd.AddCommand(generateCmd, migrateCmd, versionCmd) 62 | 63 | if err := rootCmd.Execute(); err != nil { 64 | log.Fatal(err) 65 | } 66 | } 67 | 68 | var formatErr = errors.New("invalid connection string format") 69 | 70 | func mkDsn(connect, dbname string) string { 71 | parts := strings.Split(connect, "@") 72 | if len(parts) < 2 { 73 | log.Fatal(formatErr) 74 | } 75 | 76 | credentials := strings.Split(parts[0], ":") 77 | if len(credentials) < 2 { 78 | log.Fatal(formatErr) 79 | } 80 | database := strings.Split(parts[1], ":") 81 | if len(database) < 2 { 82 | log.Fatal(formatErr) 83 | } 84 | 85 | return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true", credentials[0], credentials[1], database[0], database[1], dbname) 86 | } 87 | 88 | func connect() { 89 | // connect to database 90 | var err error 91 | database, err = sql.Open("mysql", mkDsn(*conn, *dbName)) 92 | if err != nil { 93 | log.Fatal(err) 94 | } 95 | 96 | // check for a valid connection 97 | if err := database.Ping(); err != nil { 98 | log.Fatal(err) 99 | } 100 | } 101 | 102 | func validate() { 103 | if dbName == nil || *dbName == "" { 104 | log.Fatal("Please provide a database name") 105 | } 106 | if conn == nil || *conn == "" { 107 | log.Fatal("Please provide a connection string") 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /migrate.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "path/filepath" 8 | "regexp" 9 | "strings" 10 | "time" 11 | 12 | "github.com/spf13/cobra" 13 | "sort" 14 | ) 15 | 16 | func migrate(cmd *cobra.Command, args []string) { 17 | validate() 18 | connect() 19 | tables := getTables() 20 | makeMigrations(tables, *output) 21 | } 22 | 23 | var autoincrementRegExp = regexp.MustCompile(`(?ms) AUTO_INCREMENT=[0-9]*\b`) 24 | 25 | // if the folder you are trying to output the migrations in already exists 26 | // archive will move the previous migrations into a timestamped archived folder 27 | // so you can do easy rollbacks 28 | func archive(folder string) { 29 | f, err := os.Stat(folder) 30 | if err != nil || !f.IsDir() { 31 | return 32 | } 33 | archive := fmt.Sprintf("%s_%s", folder, time.Now().Format("2006_01_02_15_04_05")) 34 | if err := os.Rename(folder, archive); err != nil { 35 | log.Fatalf("cannot archive %s folder", folder) 36 | } 37 | } 38 | 39 | type statement struct { 40 | tbl string 41 | stmt string 42 | order int 43 | } 44 | type statements []statement 45 | 46 | func makeMigrations(tables map[string]string, dst string) { 47 | archive(dst) 48 | os.Mkdir(dst, 0777) 49 | now := time.Now().Unix() 50 | 51 | var sts statements 52 | 53 | for table, comment := range tables { 54 | // get the create statement 55 | row := database.QueryRow(fmt.Sprintf("SHOW CREATE TABLE `%s`", table)) 56 | var tbl, stmt string 57 | row.Scan(&tbl, &stmt) 58 | order := GetOrderFromComment(comment) 59 | st := statement{tbl, stmt, order} 60 | sts = append(sts, st) 61 | } 62 | sort.Slice(sts, func(i, j int) bool { 63 | return sts[i].order < sts[j].order 64 | }) 65 | 66 | for _, st := range sts { 67 | // Create the up migration 68 | where := filepath.Join(dst, fmt.Sprintf("%d_create_%s.up.sql", now, st.tbl)) 69 | up, err := os.Create(where) 70 | if err != nil { 71 | log.Fatal(err) 72 | } 73 | auto := autoincrementRegExp.FindString(st.stmt) 74 | st.stmt = strings.Replace(st.stmt, auto, "", 1) 75 | _, err = up.WriteString(st.stmt + ";") 76 | if err != nil { 77 | log.Fatal(err) 78 | } 79 | // Create the down migration 80 | where = filepath.Join(dst, fmt.Sprintf("%d_create_%s.down.sql", now, st.tbl)) 81 | down, err := os.Create(where) 82 | if err != nil { 83 | log.Fatal(err) 84 | } 85 | _, err = down.WriteString(fmt.Sprintf("DROP TABLE IF EXISTS %s;", st.tbl)) 86 | if err != nil { 87 | log.Fatal(err) 88 | } 89 | 90 | // Ensure the time increments properly 91 | now += 1 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /sqltypes/sqltypes.go: -------------------------------------------------------------------------------- 1 | package sqltypes 2 | 3 | import ( 4 | "log" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // Explain wraps the explain query results for a given table 10 | type Explain struct { 11 | Field *string 12 | Type *string 13 | Null *string 14 | Key *string 15 | Default *string 16 | Extra *string 17 | } 18 | 19 | // SQLType unwraps a SQL data type 20 | type SQLType struct { 21 | notNull string 22 | nullable string 23 | } 24 | 25 | var dateType = SQLType{"time.Time", "NullTime"} 26 | var stringType = SQLType{"string", "NullString"} 27 | var byteSliceType = SQLType{"[]byte", "[]byte"} 28 | var intType = SQLType{"int64", "NullInt64"} 29 | var boolType = SQLType{"bool", "NullBool"} 30 | var floatType = SQLType{"float64", "NullFloat64"} 31 | var jsonType = SQLType{"RawJSON", "RawJSON"} 32 | 33 | var dataTypes = map[string]SQLType{ 34 | "char": stringType, 35 | "varchar": stringType, 36 | 37 | "tinytext": stringType, 38 | "text": stringType, 39 | "mediumtext": stringType, 40 | "longtext": stringType, 41 | 42 | "json": jsonType, 43 | 44 | "enum": stringType, 45 | "set": stringType, 46 | 47 | //"geometry": stringType, 48 | //"point": stringType, 49 | //"linestring": stringType, 50 | //"polygon": stringType, 51 | //"multipoint": stringType, 52 | //"multilinestring": stringType, 53 | //"multipolygon": stringType, 54 | //"geometrycollection": stringType, 55 | 56 | "bit": byteSliceType, 57 | "binary": byteSliceType, 58 | "varbinary": byteSliceType, 59 | "tinyblob": byteSliceType, 60 | "mediumblob": byteSliceType, 61 | "blob": byteSliceType, 62 | "longblob": byteSliceType, 63 | 64 | "tinyint_as_bool": boolType, 65 | "tinyint": intType, 66 | "smallint": intType, 67 | "mediumint": intType, 68 | "int": intType, 69 | "bigint": intType, 70 | 71 | "float": floatType, 72 | "double": floatType, 73 | "decimal": floatType, 74 | 75 | "date": dateType, 76 | "datetime": dateType, 77 | "timestamp": dateType, 78 | "time": stringType, 79 | "year": intType, 80 | } 81 | 82 | // AssertType figures out which go type should be used, based on the SQL type. 83 | func AssertType(columnType string, nullable string) string { 84 | nul := nullable == "YES" 85 | 86 | bits := strings.Split(columnType, "(") 87 | extractedType := bits[0] 88 | var extractedLength int 89 | if len(bits) > 1 { 90 | idx := strings.Index(bits[1], ")") 91 | inner := bits[1][:idx] 92 | 93 | // ignoring error here because if any length cannot be found, 94 | // this does not constitute an error, but an expected outcome 95 | extractedLength, _ = strconv.Atoi(inner) 96 | if extractedType == "tinyint" && extractedLength == 1 { 97 | extractedType = "tinyint_as_bool" 98 | } 99 | } 100 | 101 | for dataType, sqlType := range dataTypes { 102 | if extractedType == dataType { 103 | if nul { 104 | return sqlType.nullable 105 | } 106 | return sqlType.notNull 107 | } 108 | } 109 | log.Fatalf("unsupported type: %v, please raise an issue with us if you'd like to request support.", extractedType) 110 | return "" 111 | } 112 | 113 | // NeedsImport handles adding the imports for types that require them. 114 | func NeedsImport(typ string) (imp string, ok bool) { 115 | switch typ { 116 | case "time.Time": 117 | return "time", true 118 | case "json.RawMessage": 119 | return "encoding/json", true 120 | default: 121 | return 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /tmpl/types.go: -------------------------------------------------------------------------------- 1 | package tmpl 2 | 3 | // TmplStructs is a collection on TmplStruct 4 | type TmplStructs []TmplStruct 5 | 6 | // TmplStruct defines the table data to pass to the models 7 | type TmplStruct struct { 8 | Name string 9 | TableName string 10 | Fields []TmplField 11 | Imports map[string]struct{} 12 | } 13 | 14 | // TmplField defines a table field template 15 | type TmplField struct { 16 | Name string 17 | Type string 18 | ColumnName string 19 | Nullable bool 20 | } 21 | 22 | // StructTmplData defines the top level struct data to pass to the models 23 | type StructTmplData struct { 24 | Model TmplStruct 25 | Receiver string 26 | PackageName string 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Issue description 2 | Tell us what should happen and what happens instead 3 | 4 | ### Example code 5 | ```go 6 | If possible, please enter some example code here to reproduce the issue. 7 | ``` 8 | 9 | ### Error log 10 | ``` 11 | If you have an error log, please paste it here. 12 | ``` 13 | 14 | ### Configuration 15 | *Driver version (or git SHA):* 16 | 17 | *Go version:* run `go version` in your console 18 | 19 | *Server version:* E.g. MySQL 5.6, MariaDB 10.0.20 20 | 21 | *Server OS:* E.g. Debian 8.1 (Jessie), Windows 10 22 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | Please explain the changes you made here. 3 | 4 | ### Checklist 5 | - [ ] Code compiles correctly 6 | - [ ] Created tests which fail without the change (if possible) 7 | - [ ] All tests passing 8 | - [ ] Extended the README / documentation, if necessary 9 | - [ ] Added myself / the copyright holder to the AUTHORS file 10 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .DS_Store? 3 | ._* 4 | .Spotlight-V100 5 | .Trashes 6 | Icon? 7 | ehthumbs.db 8 | Thumbs.db 9 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - 1.5 8 | - 1.6 9 | - 1.7 10 | - tip 11 | 12 | before_script: 13 | - mysql -e 'create database gotest;' 14 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of Go-MySQL-Driver authors for copyright purposes. 2 | 3 | # If you are submitting a patch, please add your name or the name of the 4 | # organization which holds the copyright to this list in alphabetical order. 5 | 6 | # Names should be added to this file as 7 | # Name 8 | # The email address is not required for organizations. 9 | # Please keep the list sorted. 10 | 11 | 12 | # Individual Persons 13 | 14 | Aaron Hopkins 15 | Arne Hormann 16 | Carlos Nieto 17 | Chris Moos 18 | Daniel Nichter 19 | Daniël van Eeden 20 | DisposaBoy 21 | Frederick Mayle 22 | Gustavo Kristic 23 | Hanno Braun 24 | Henri Yandell 25 | Hirotaka Yamamoto 26 | INADA Naoki 27 | James Harr 28 | Jian Zhen 29 | Joshua Prunier 30 | Julien Lefevre 31 | Julien Schmidt 32 | Kamil Dziedzic 33 | Kevin Malachowski 34 | Lennart Rudolph 35 | Leonardo YongUk Kim 36 | Luca Looz 37 | Lucas Liu 38 | Luke Scott 39 | Michael Woolnough 40 | Nicola Peduzzi 41 | Olivier Mengué 42 | Paul Bonser 43 | Runrioter Wung 44 | Soroush Pour 45 | Stan Putrya 46 | Stanley Gunawan 47 | Xiangyu Hu 48 | Xiaobing Jiang 49 | Xiuming Chen 50 | Zhenye Xie 51 | 52 | # Organizations 53 | 54 | Barracuda Networks, Inc. 55 | Google Inc. 56 | Stripe Inc. 57 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | ## Reporting Issues 4 | 5 | Before creating a new Issue, please check first if a similar Issue [already exists](https://github.com/go-sql-driver/mysql/issues?state=open) or was [recently closed](https://github.com/go-sql-driver/mysql/issues?direction=desc&page=1&sort=updated&state=closed). 6 | 7 | ## Contributing Code 8 | 9 | By contributing to this project, you share your code under the Mozilla Public License 2, as specified in the LICENSE file. 10 | Don't forget to add yourself to the AUTHORS file. 11 | 12 | ### Code Review 13 | 14 | Everyone is invited to review and comment on pull requests. 15 | If it looks fine to you, comment with "LGTM" (Looks good to me). 16 | 17 | If changes are required, notice the reviewers with "PTAL" (Please take another look) after committing the fixes. 18 | 19 | Before merging the Pull Request, at least one [team member](https://github.com/go-sql-driver?tab=members) must have commented with "LGTM". 20 | 21 | ## Development Ideas 22 | 23 | If you are looking for ideas for code contributions, please check our [Development Ideas](https://github.com/go-sql-driver/mysql/wiki/Development-Ideas) Wiki page. 24 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/appengine.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | // +build appengine 10 | 11 | package mysql 12 | 13 | import ( 14 | "appengine/cloudsql" 15 | ) 16 | 17 | func init() { 18 | RegisterDial("cloudsql", cloudsql.Dial) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/connection_test.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2016 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | import ( 12 | "database/sql/driver" 13 | "testing" 14 | ) 15 | 16 | func TestInterpolateParams(t *testing.T) { 17 | mc := &mysqlConn{ 18 | buf: newBuffer(nil), 19 | maxAllowedPacket: maxPacketSize, 20 | cfg: &Config{ 21 | InterpolateParams: true, 22 | }, 23 | } 24 | 25 | q, err := mc.interpolateParams("SELECT ?+?", []driver.Value{int64(42), "gopher"}) 26 | if err != nil { 27 | t.Errorf("Expected err=nil, got %#v", err) 28 | return 29 | } 30 | expected := `SELECT 42+'gopher'` 31 | if q != expected { 32 | t.Errorf("Expected: %q\nGot: %q", expected, q) 33 | } 34 | } 35 | 36 | func TestInterpolateParamsTooManyPlaceholders(t *testing.T) { 37 | mc := &mysqlConn{ 38 | buf: newBuffer(nil), 39 | maxAllowedPacket: maxPacketSize, 40 | cfg: &Config{ 41 | InterpolateParams: true, 42 | }, 43 | } 44 | 45 | q, err := mc.interpolateParams("SELECT ?+?", []driver.Value{int64(42)}) 46 | if err != driver.ErrSkip { 47 | t.Errorf("Expected err=driver.ErrSkip, got err=%#v, q=%#v", err, q) 48 | } 49 | } 50 | 51 | // We don't support placeholder in string literal for now. 52 | // https://github.com/go-sql-driver/mysql/pull/490 53 | func TestInterpolateParamsPlaceholderInString(t *testing.T) { 54 | mc := &mysqlConn{ 55 | buf: newBuffer(nil), 56 | maxAllowedPacket: maxPacketSize, 57 | cfg: &Config{ 58 | InterpolateParams: true, 59 | }, 60 | } 61 | 62 | q, err := mc.interpolateParams("SELECT 'abc?xyz',?", []driver.Value{int64(42)}) 63 | // When InterpolateParams support string literal, this should return `"SELECT 'abc?xyz', 42` 64 | if err != driver.ErrSkip { 65 | t.Errorf("Expected err=driver.ErrSkip, got err=%#v, q=%#v", err, q) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/errors_test.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | import ( 12 | "bytes" 13 | "log" 14 | "testing" 15 | ) 16 | 17 | func TestErrorsSetLogger(t *testing.T) { 18 | previous := errLog 19 | defer func() { 20 | errLog = previous 21 | }() 22 | 23 | // set up logger 24 | const expected = "prefix: test\n" 25 | buffer := bytes.NewBuffer(make([]byte, 0, 64)) 26 | logger := log.New(buffer, "prefix: ", 0) 27 | 28 | // print 29 | SetLogger(logger) 30 | errLog.Print("test") 31 | 32 | // check result 33 | if actual := buffer.String(); actual != expected { 34 | t.Errorf("expected %q, got %q", expected, actual) 35 | } 36 | } 37 | 38 | func TestErrorsStrictIgnoreNotes(t *testing.T) { 39 | runTests(t, dsn+"&sql_notes=false", func(dbt *DBTest) { 40 | dbt.mustExec("DROP TABLE IF EXISTS does_not_exist") 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/result.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | type mysqlResult struct { 12 | affectedRows int64 13 | insertId int64 14 | } 15 | 16 | func (res *mysqlResult) LastInsertId() (int64, error) { 17 | return res.insertId, nil 18 | } 19 | 20 | func (res *mysqlResult) RowsAffected() (int64, error) { 21 | return res.affectedRows, nil 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/rows.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | import ( 12 | "database/sql/driver" 13 | "io" 14 | ) 15 | 16 | type mysqlField struct { 17 | tableName string 18 | name string 19 | flags fieldFlag 20 | fieldType byte 21 | decimals byte 22 | } 23 | 24 | type mysqlRows struct { 25 | mc *mysqlConn 26 | columns []mysqlField 27 | } 28 | 29 | type binaryRows struct { 30 | mysqlRows 31 | } 32 | 33 | type textRows struct { 34 | mysqlRows 35 | } 36 | 37 | type emptyRows struct{} 38 | 39 | func (rows *mysqlRows) Columns() []string { 40 | columns := make([]string, len(rows.columns)) 41 | if rows.mc != nil && rows.mc.cfg.ColumnsWithAlias { 42 | for i := range columns { 43 | if tableName := rows.columns[i].tableName; len(tableName) > 0 { 44 | columns[i] = tableName + "." + rows.columns[i].name 45 | } else { 46 | columns[i] = rows.columns[i].name 47 | } 48 | } 49 | } else { 50 | for i := range columns { 51 | columns[i] = rows.columns[i].name 52 | } 53 | } 54 | return columns 55 | } 56 | 57 | func (rows *mysqlRows) Close() error { 58 | mc := rows.mc 59 | if mc == nil { 60 | return nil 61 | } 62 | if mc.netConn == nil { 63 | return ErrInvalidConn 64 | } 65 | 66 | // Remove unread packets from stream 67 | err := mc.readUntilEOF() 68 | if err == nil { 69 | if err = mc.discardResults(); err != nil { 70 | return err 71 | } 72 | } 73 | 74 | rows.mc = nil 75 | return err 76 | } 77 | 78 | func (rows *binaryRows) Next(dest []driver.Value) error { 79 | if mc := rows.mc; mc != nil { 80 | if mc.netConn == nil { 81 | return ErrInvalidConn 82 | } 83 | 84 | // Fetch next row from stream 85 | return rows.readRow(dest) 86 | } 87 | return io.EOF 88 | } 89 | 90 | func (rows *textRows) Next(dest []driver.Value) error { 91 | if mc := rows.mc; mc != nil { 92 | if mc.netConn == nil { 93 | return ErrInvalidConn 94 | } 95 | 96 | // Fetch next row from stream 97 | return rows.readRow(dest) 98 | } 99 | return io.EOF 100 | } 101 | 102 | func (rows emptyRows) Columns() []string { 103 | return nil 104 | } 105 | 106 | func (rows emptyRows) Close() error { 107 | return nil 108 | } 109 | 110 | func (rows emptyRows) Next(dest []driver.Value) error { 111 | return io.EOF 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/go-sql-driver/mysql/transaction.go: -------------------------------------------------------------------------------- 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 | // 3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 | // 5 | // This Source Code Form is subject to the terms of the Mozilla Public 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | // You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | package mysql 10 | 11 | type mysqlTx struct { 12 | mc *mysqlConn 13 | } 14 | 15 | func (tx *mysqlTx) Commit() (err error) { 16 | if tx.mc == nil || tx.mc.netConn == nil { 17 | return ErrInvalidConn 18 | } 19 | err = tx.mc.exec("COMMIT") 20 | tx.mc = nil 21 | return 22 | } 23 | 24 | func (tx *mysqlTx) Rollback() (err error) { 25 | if tx.mc == nil || tx.mc.netConn == nil { 26 | return ErrInvalidConn 27 | } 28 | err = tx.mc.exec("ROLLBACK") 29 | tx.mc = nil 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/envy/.env: -------------------------------------------------------------------------------- 1 | # This is a comment 2 | # We can use equal or colon notation 3 | DIR: root 4 | FLAVOUR: none 5 | INSIDE_FOLDER=false -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/envy/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | doc 4 | tmp 5 | pkg 6 | *.gem 7 | *.pid 8 | coverage 9 | coverage.data 10 | build/* 11 | *.pbxuser 12 | *.mode1v3 13 | .svn 14 | profile 15 | .console_history 16 | .sass-cache/* 17 | .rake_tasks~ 18 | *.log.lck 19 | solr/ 20 | .jhw-cache/ 21 | jhw.* 22 | *.sublime* 23 | node_modules/ 24 | dist/ 25 | generated/ 26 | .vendor/ 27 | bin/* 28 | gin-bin 29 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/envy/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | sudo: false 4 | 5 | go: 6 | - 1.7 7 | - 1.8 8 | - tip 9 | 10 | matrix: 11 | allow_failures: 12 | - go: 'tip' 13 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/envy/README.md: -------------------------------------------------------------------------------- 1 | # envy 2 | 3 | Envy makes working with ENV variables in Go trivial. 4 | 5 | * Get ENV variables with default values. 6 | * Set ENV variables safely without affecting the underlying system. 7 | * Temporarily change ENV vars; useful for testing. 8 | * Map all of the key/values in the ENV. 9 | * Loads .env files (by using [godotenv](https://github.com/joho/godotenv/)) 10 | * More! 11 | 12 | ## Installation 13 | 14 | ```text 15 | $ go get -u github.com/gobuffalo/envy 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```go 21 | func Test_Get(t *testing.T) { 22 | r := require.New(t) 23 | r.NotZero(os.Getenv("GOPATH")) 24 | r.Equal(os.Getenv("GOPATH"), envy.Get("GOPATH", "foo")) 25 | r.Equal("bar", envy.Get("IDONTEXIST", "bar")) 26 | } 27 | 28 | func Test_MustGet(t *testing.T) { 29 | r := require.New(t) 30 | r.NotZero(os.Getenv("GOPATH")) 31 | v, err := envy.MustGet("GOPATH") 32 | r.NoError(err) 33 | r.Equal(os.Getenv("GOPATH"), v) 34 | 35 | _, err = envy.MustGet("IDONTEXIST") 36 | r.Error(err) 37 | } 38 | 39 | func Test_Set(t *testing.T) { 40 | r := require.New(t) 41 | _, err := envy.MustGet("FOO") 42 | r.Error(err) 43 | 44 | envy.Set("FOO", "foo") 45 | r.Equal("foo", envy.Get("FOO", "bar")) 46 | } 47 | 48 | func Test_Temp(t *testing.T) { 49 | r := require.New(t) 50 | 51 | _, err := envy.MustGet("BAR") 52 | r.Error(err) 53 | 54 | envy.Temp(func() { 55 | envy.Set("BAR", "foo") 56 | r.Equal("foo", envy.Get("BAR", "bar")) 57 | _, err = envy.MustGet("BAR") 58 | r.NoError(err) 59 | }) 60 | 61 | _, err = envy.MustGet("BAR") 62 | r.Error(err) 63 | } 64 | ``` 65 | ## .env files support 66 | 67 | Envy now supports loading `.env` files by using the [godotenv library](https://github.com/joho/godotenv/). 68 | That means one can use and define multiple `.env` files which will be loaded on-demand. By default, no env files will be loaded. To load one or more, you need to call the `envy.Load` function in one of the following ways: 69 | 70 | ```go 71 | envy.Load() // 1 72 | 73 | envy.Load("MY_ENV_FILE") // 2 74 | 75 | envy.Load(".env", ".env.prod") // 3 76 | 77 | envy.Load(".env", "NON_EXISTING_FILE") // 4 78 | 79 | // 5 80 | envy.Load(".env") 81 | envy.Load("NON_EXISTING_FILE") 82 | 83 | // 6 84 | envy.Load(".env", "NON_EXISTING_FILE", ".env.prod") 85 | ``` 86 | 87 | 1. Will load the default `.env` file 88 | 2. Will load the file `MY_ENV_FILE`, **but not** `.env` 89 | 3. Will load the file `.env`, and after that will load the `.env.prod` file. If any variable is redefined in `. env.prod` it will be overwritten (will contain the `env.prod` value) 90 | 4. Will load the `.env` file and return an error as the second file does not exist. The values in `.env` will be loaded and available. 91 | 5. Same as 4 92 | 6. Will load the `.env` file and return an error as the second file does not exist. The values in `.env` will be loaded and available, **but the ones in** `.env.prod` **won't**. -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/envy/test_env/.env: -------------------------------------------------------------------------------- 1 | DIR=test_env 2 | FLAVOUR=none 3 | INSIDE_FOLDER=true -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/envy/test_env/.env.prod: -------------------------------------------------------------------------------- 1 | FLAVOUR=production -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/.codeclimate.yml: -------------------------------------------------------------------------------- 1 | --- 2 | engines: 3 | golint: 4 | enabled: true 5 | checks: 6 | GoLint/Naming/MixedCaps: 7 | enabled: false 8 | govet: 9 | enabled: true 10 | gofmt: 11 | enabled: true 12 | fixme: 13 | enabled: true 14 | ratings: 15 | paths: 16 | - "**.go" 17 | exclude_paths: 18 | - "**/*_test.go" 19 | - "*_test.go" 20 | - "fixtures/" 21 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | doc 4 | tmp 5 | pkg 6 | *.gem 7 | *.pid 8 | coverage 9 | coverage.data 10 | build/* 11 | *.pbxuser 12 | *.mode1v3 13 | .svn 14 | profile 15 | .console_history 16 | .sass-cache/* 17 | .rake_tasks~ 18 | *.log.lck 19 | solr/ 20 | .jhw-cache/ 21 | jhw.* 22 | *.sublime* 23 | node_modules/ 24 | dist/ 25 | generated/ 26 | .vendor/ 27 | bin/* 28 | gin-bin 29 | /packr_darwin_amd64 30 | /packr_linux_amd64 31 | .vscode/ 32 | debug.test 33 | .grifter/ 34 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/.goreleaser.yml: -------------------------------------------------------------------------------- 1 | project_name: packr 2 | release: 3 | github: 4 | owner: gobuffalo 5 | name: packr 6 | name_template: '{{.Tag}}' 7 | brew: 8 | commit_author: 9 | name: goreleaserbot 10 | email: goreleaser@carlosbecker.com 11 | install: bin.install "packr" 12 | builds: 13 | - 14 | goos: 15 | - linux 16 | - darwin 17 | - windows 18 | goarch: 19 | - amd64 20 | - "386" 21 | goarm: 22 | - "6" 23 | main: ./packr/main.go 24 | binary: packr 25 | hooks: 26 | pre: packr 27 | post: packr clean 28 | archive: 29 | name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm 30 | }}v{{ .Arm }}{{ end }}' 31 | format: tar.gz 32 | files: 33 | - licence* 34 | - LICENCE* 35 | - license* 36 | - LICENSE* 37 | - readme* 38 | - README* 39 | - changelog* 40 | - CHANGELOG* 41 | fpm: 42 | name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm 43 | }}v{{ .Arm }}{{ end }}' 44 | bindir: /usr/local/bin 45 | snapcraft: 46 | name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm 47 | }}v{{ .Arm }}{{ end }}' 48 | snapshot: 49 | name_template: SNAPSHOT-{{ .Commit }} 50 | checksum: 51 | name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt' 52 | dist: dist 53 | sign: 54 | cmd: gpg 55 | args: 56 | - --output 57 | - $signature 58 | - --detach-sig 59 | - $artifact 60 | signature: ${artifact}.sig 61 | artifacts: none 62 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | sudo: false 4 | 5 | go: 6 | - 1.8 7 | - 1.9 8 | - tip 9 | 10 | matrix: 11 | allow_failures: 12 | - go: 'tip' 13 | 14 | script: 15 | - go test -v ./... 16 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Mark Bates 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/box_test.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "os" 7 | "runtime" 8 | "sort" 9 | "strings" 10 | "testing" 11 | 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | func Test_Box_String(t *testing.T) { 16 | r := require.New(t) 17 | s := testBox.String("hello.txt") 18 | r.Equal("hello world!", strings.TrimSpace(s)) 19 | } 20 | 21 | func Test_Box_MustString(t *testing.T) { 22 | r := require.New(t) 23 | _, err := testBox.MustString("idontexist.txt") 24 | r.Error(err) 25 | } 26 | 27 | func Test_Box_Bytes(t *testing.T) { 28 | r := require.New(t) 29 | s := testBox.Bytes("hello.txt") 30 | r.Equal([]byte("hello world!"), bytes.TrimSpace(s)) 31 | } 32 | 33 | func Test_Box_MustBytes(t *testing.T) { 34 | r := require.New(t) 35 | _, err := testBox.MustBytes("idontexist.txt") 36 | r.Error(err) 37 | } 38 | 39 | func Test_Box_Has(t *testing.T) { 40 | r := require.New(t) 41 | r.True(testBox.Has("hello.txt")) 42 | r.False(testBox.Has("idontexist.txt")) 43 | } 44 | 45 | func Test_Box_Walk_Physical(t *testing.T) { 46 | r := require.New(t) 47 | count := 0 48 | err := testBox.Walk(func(path string, f File) error { 49 | count++ 50 | return nil 51 | }) 52 | r.NoError(err) 53 | r.Equal(3, count) 54 | } 55 | 56 | func Test_Box_Walk_Virtual(t *testing.T) { 57 | r := require.New(t) 58 | count := 0 59 | err := virtualBox.Walk(func(path string, f File) error { 60 | count++ 61 | return nil 62 | }) 63 | r.NoError(err) 64 | r.Equal(4, count) 65 | } 66 | 67 | func Test_List_Virtual(t *testing.T) { 68 | r := require.New(t) 69 | mustHave := []string{"a", "b", "c", "d/a"} 70 | actual := virtualBox.List() 71 | sort.Strings(actual) 72 | r.Equal(mustHave, actual) 73 | } 74 | 75 | func Test_List_Physical(t *testing.T) { 76 | r := require.New(t) 77 | mustHave := []string{"goodbye.txt", "hello.txt", "index.html"} 78 | actual := testBox.List() 79 | r.Equal(mustHave, actual) 80 | } 81 | 82 | func Test_Outside_Box(t *testing.T) { 83 | r := require.New(t) 84 | f, err := ioutil.TempFile("", "") 85 | r.NoError(err) 86 | defer os.RemoveAll(f.Name()) 87 | _, err = testBox.MustString(f.Name()) 88 | r.Error(err) 89 | } 90 | 91 | func Test_Box_find(t *testing.T) { 92 | box := NewBox("./example") 93 | 94 | onWindows := runtime.GOOS == "windows" 95 | table := []struct { 96 | name string 97 | found bool 98 | }{ 99 | {"assets/app.css", true}, 100 | {"assets\\app.css", onWindows}, 101 | {"foo/bar.baz", false}, 102 | } 103 | 104 | for _, tt := range table { 105 | t.Run(tt.name, func(st *testing.T) { 106 | r := require.New(st) 107 | _, err := box.find(tt.name) 108 | if tt.found { 109 | r.True(box.Has(tt.name)) 110 | r.NoError(err) 111 | } else { 112 | r.False(box.Has(tt.name)) 113 | r.Error(err) 114 | } 115 | }) 116 | } 117 | } 118 | 119 | func Test_Virtual_Directory_Not_Found(t *testing.T) { 120 | r := require.New(t) 121 | _, err := virtualBox.find("d") 122 | r.NoError(err) 123 | _, err = virtualBox.find("does-not-exist") 124 | r.Error(err) 125 | } -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/builder/box.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | import ( 4 | "encoding/json" 5 | "io/ioutil" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | 10 | "bytes" 11 | "compress/gzip" 12 | 13 | "github.com/pkg/errors" 14 | ) 15 | 16 | type box struct { 17 | Name string 18 | Files []file 19 | compress bool 20 | } 21 | 22 | func (b *box) Walk(root string) error { 23 | root, err := filepath.EvalSymlinks(root) 24 | if err != nil { 25 | return errors.WithStack(err) 26 | } 27 | if _, err := os.Stat(root); err != nil { 28 | // return nil 29 | return errors.Errorf("could not find folder for box: %s", root) 30 | } 31 | return filepath.Walk(root, func(path string, info os.FileInfo, err error) error { 32 | if info == nil || info.IsDir() || strings.HasSuffix(info.Name(), "-packr.go") { 33 | return nil 34 | } 35 | name := strings.Replace(path, root+string(os.PathSeparator), "", 1) 36 | name = strings.Replace(name, "\\", "/", -1) 37 | f := file{ 38 | Name: name, 39 | } 40 | 41 | bb, err := ioutil.ReadFile(path) 42 | if err != nil { 43 | return errors.WithStack(err) 44 | } 45 | if b.compress { 46 | bb, err = compressFile(bb) 47 | if err != nil { 48 | return errors.WithStack(err) 49 | } 50 | } 51 | bb, err = json.Marshal(bb) 52 | if err != nil { 53 | return errors.WithStack(err) 54 | } 55 | f.Contents = strings.Replace(string(bb), "\"", "\\\"", -1) 56 | 57 | b.Files = append(b.Files, f) 58 | return nil 59 | }) 60 | } 61 | 62 | func compressFile(bb []byte) ([]byte, error) { 63 | var buf bytes.Buffer 64 | writer := gzip.NewWriter(&buf) 65 | _, err := writer.Write(bb) 66 | if err != nil { 67 | return bb, errors.WithStack(err) 68 | } 69 | err = writer.Close() 70 | if err != nil { 71 | return bb, errors.WithStack(err) 72 | } 73 | return buf.Bytes(), nil 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/builder/builder_test.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "io/ioutil" 7 | "os" 8 | "os/exec" 9 | "path/filepath" 10 | "testing" 11 | 12 | "github.com/gobuffalo/envy" 13 | "github.com/stretchr/testify/require" 14 | ) 15 | 16 | func Test_Builder_Run(t *testing.T) { 17 | r := require.New(t) 18 | 19 | root := filepath.Join("..", "example") 20 | defer Clean(root) 21 | 22 | exPackr := filepath.Join(root, "example-packr.go") 23 | r.False(fileExists(exPackr)) 24 | 25 | fooPackr := filepath.Join(root, "foo", "foo-packr.go") 26 | r.False(fileExists(fooPackr)) 27 | 28 | b := New(context.Background(), root) 29 | err := b.Run() 30 | r.NoError(err) 31 | 32 | r.True(fileExists(exPackr)) 33 | r.True(fileExists(fooPackr)) 34 | 35 | bb, err := ioutil.ReadFile(exPackr) 36 | r.NoError(err) 37 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("./assets", "app.css", "\"Ym9ke`))) 38 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("./assets", "app.js", "\"YWxlcn`))) 39 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("./templates", "index.html", "\"PCFET0NUWVBF`))) 40 | 41 | bb, err = ioutil.ReadFile(fooPackr) 42 | r.NoError(err) 43 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("../assets", "app.css", "\"Ym9keS`))) 44 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("../assets", "app.js", "\"YWxlcn`))) 45 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("../templates", "index.html", "\"PCFET0NUW`))) 46 | } 47 | 48 | func Test_Builder_Run_Compress(t *testing.T) { 49 | r := require.New(t) 50 | 51 | root := filepath.Join("..", "example") 52 | defer Clean(root) 53 | 54 | exPackr := filepath.Join(root, "example-packr.go") 55 | r.False(fileExists(exPackr)) 56 | 57 | fooPackr := filepath.Join(root, "foo", "foo-packr.go") 58 | r.False(fileExists(fooPackr)) 59 | 60 | b := New(context.Background(), root) 61 | b.Compress = true 62 | err := b.Run() 63 | r.NoError(err) 64 | 65 | r.True(fileExists(exPackr)) 66 | r.True(fileExists(fooPackr)) 67 | 68 | bb, err := ioutil.ReadFile(exPackr) 69 | r.NoError(err) 70 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("./assets", "app.css", "\"H4sIAAAAAAAA/0rKT`))) 71 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("./assets", "app.js", "\"H4sIAAAAAAAA/0rMSS`))) 72 | 73 | bb, err = ioutil.ReadFile(fooPackr) 74 | r.NoError(err) 75 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("../assets", "app.css", "\"H4sIAAAAAAAA/0rKT`))) 76 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("../assets", "app.js", "\"H4sIAAAAAAAA/0rMSS`))) 77 | r.True(bytes.Contains(bb, []byte(`packr.PackJSONBytes("../templates", "index.html", "\"H4sIAAAAAAAA`))) 78 | } 79 | 80 | func Test_Binary_Builds(t *testing.T) { 81 | r := require.New(t) 82 | pwd, _ := os.Getwd() 83 | defer os.Chdir(pwd) 84 | 85 | root := "../example" 86 | defer Clean(root) 87 | defer os.RemoveAll(filepath.Join(root, "bin")) 88 | 89 | b := New(context.Background(), root) 90 | err := b.Run() 91 | r.NoError(err) 92 | 93 | os.Chdir(root) 94 | cmd := exec.Command(envy.Get("GO_BIN", "go"), "build", "-v", "-o", "bin/example") 95 | err = cmd.Run() 96 | r.NoError(err) 97 | 98 | r.True(fileExists("bin/example")) 99 | } 100 | 101 | func fileExists(path string) bool { 102 | _, err := os.Stat(path) 103 | return err == nil 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/builder/clean.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "strings" 8 | 9 | "github.com/pkg/errors" 10 | ) 11 | 12 | // Clean up an *-packr.go files 13 | func Clean(root string) { 14 | root, _ = filepath.EvalSymlinks(root) 15 | filepath.Walk(root, func(path string, info os.FileInfo, err error) error { 16 | base := filepath.Base(path) 17 | if base == ".git" || base == "vendor" || base == "node_modules" { 18 | return filepath.SkipDir 19 | } 20 | if info == nil || info.IsDir() { 21 | return nil 22 | } 23 | if strings.Contains(base, "-packr.go") { 24 | err := os.Remove(path) 25 | if err != nil { 26 | fmt.Println(err) 27 | return errors.WithStack(err) 28 | } 29 | } 30 | return nil 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/builder/file.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | type file struct { 4 | Name string 5 | Contents string 6 | } 7 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/builder/pkg.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | type pkg struct { 4 | Name string 5 | Dir string 6 | Boxes []box 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/builder/tmpl.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | var tmpl = `package {{.Name}} 4 | 5 | import "github.com/gobuffalo/packr" 6 | 7 | // !!! GENERATED FILE !!! 8 | // Do NOT hand edit this file!! 9 | // It is recommended that you DO NOT check into this file into SCM. 10 | // We STRONGLY recommend you delete this file after you have built your 11 | // Go binary. You can use the "packr clean" command to clean up this, 12 | // and any other packr generated files. 13 | func init() { 14 | {{ range $box := .Boxes -}} 15 | {{range .Files -}} 16 | packr.PackJSONBytes("{{$box.Name}}", "{{.Name}}", "{{.Contents}}") 17 | {{end -}} 18 | {{end -}} 19 | } 20 | ` 21 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/builder/visitor_test.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | ) 8 | 9 | func Test_Visitor(t *testing.T) { 10 | r := require.New(t) 11 | v := newVisitor("../example/example.go") 12 | r.NoError(v.Run()) 13 | 14 | r.Equal("example", v.Package) 15 | r.Len(v.Errors, 0) 16 | r.Len(v.Boxes, 5) 17 | r.Equal([]string{"./assets", "./bar", "./foo", "./sf", "./templates"}, v.Boxes) 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/assets/app.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: red; 3 | } 4 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/assets/app.js: -------------------------------------------------------------------------------- 1 | alert("hello!"); 2 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/bar/bar.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUSHDigital/modelgen/e964ed636889a977b7cc63ccf5a8fd1bba6783a0/vendor/github.com/gobuffalo/packr/example/bar/bar.html -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/baz/baz.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUSHDigital/modelgen/e964ed636889a977b7cc63ccf5a8fd1bba6783a0/vendor/github.com/gobuffalo/packr/example/baz/baz.html -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/example.go: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | import ( 4 | "github.com/gobuffalo/packr" 5 | ) 6 | 7 | var a = packr.NewBox("./foo") 8 | 9 | type S struct{} 10 | 11 | func (S) f(packr.Box) {} 12 | 13 | func init() { 14 | // packr.NewBox("../idontexists") 15 | 16 | b := "./baz" 17 | packr.NewBox(b) // won't work, no variables allowed, only strings 18 | 19 | foo("/templates", packr.NewBox("./templates")) 20 | packr.NewBox("./assets") 21 | 22 | packr.NewBox("./bar") 23 | 24 | s := S{} 25 | s.f(packr.NewBox("./sf")) 26 | } 27 | 28 | func foo(s string, box packr.Box) {} 29 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/foo/bar.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | import "github.com/gobuffalo/packr" 4 | 5 | func init() { 6 | packr.NewBox("../assets") 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/foo/foo.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | import "github.com/gobuffalo/packr" 4 | 5 | func init() { 6 | packr.NewBox("../templates") 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/sf/foo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Foo 7 | 8 | 9 | body 10 | 11 | 12 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/example/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INDEX 7 | link 8 | 9 | 10 | body 11 | 12 | 13 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/file.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import ( 4 | "io" 5 | "os" 6 | ) 7 | 8 | type File interface { 9 | io.ReadCloser 10 | io.Writer 11 | FileInfo() (os.FileInfo, error) 12 | Readdir(count int) ([]os.FileInfo, error) 13 | Seek(offset int64, whence int) (int64, error) 14 | Stat() (os.FileInfo, error) 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/file_info.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import ( 4 | "os" 5 | "time" 6 | ) 7 | 8 | type fileInfo struct { 9 | Path string 10 | Contents []byte 11 | size int64 12 | modTime time.Time 13 | isDir bool 14 | } 15 | 16 | func (f fileInfo) Name() string { 17 | return f.Path 18 | } 19 | 20 | func (f fileInfo) Size() int64 { 21 | return f.size 22 | } 23 | 24 | func (f fileInfo) Mode() os.FileMode { 25 | return 0444 26 | } 27 | 28 | func (f fileInfo) ModTime() time.Time { 29 | return f.modTime 30 | } 31 | 32 | func (f fileInfo) IsDir() bool { 33 | return f.isDir 34 | } 35 | 36 | func (f fileInfo) Sys() interface{} { 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/fixtures/goodbye.txt: -------------------------------------------------------------------------------- 1 | goodbye cruel world! 2 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/fixtures/hello.txt: -------------------------------------------------------------------------------- 1 | hello world! 2 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/fixtures/index.html: -------------------------------------------------------------------------------- 1 |

Index!

2 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/grifts/release.go: -------------------------------------------------------------------------------- 1 | package grifts 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "fmt" 7 | "os" 8 | "os/exec" 9 | "strings" 10 | 11 | . "github.com/markbates/grift/grift" 12 | ) 13 | 14 | var _ = Add("release", func(c *Context) error { 15 | cmd := exec.Command("git", "tag", "--list") 16 | if b, err := cmd.CombinedOutput(); err == nil { 17 | lines := bytes.Split(b, []byte("\n")) 18 | for _, l := range lines[len(lines)-6:] { 19 | fmt.Println(string(l)) 20 | } 21 | } 22 | 23 | r := bufio.NewReader(os.Stdin) 24 | fmt.Print("Enter version number (vx.x.x): ") 25 | v, _ := r.ReadString('\n') 26 | v = strings.TrimSpace(v) 27 | 28 | cmd = exec.Command("git", "tag", v) 29 | cmd.Stdin = os.Stdin 30 | cmd.Stdout = os.Stdout 31 | cmd.Stderr = os.Stderr 32 | if err := cmd.Run(); err != nil { 33 | return err 34 | } 35 | 36 | cmd = exec.Command("git", "push", "origin", "--tags") 37 | cmd.Stdin = os.Stdin 38 | cmd.Stdout = os.Stdout 39 | cmd.Stderr = os.Stderr 40 | if err := cmd.Run(); err != nil { 41 | return err 42 | } 43 | 44 | cmd = exec.Command("goreleaser", "--rm-dist") 45 | cmd.Stdin = os.Stdin 46 | cmd.Stdout = os.Stdout 47 | cmd.Stderr = os.Stderr 48 | if err := cmd.Run(); err != nil { 49 | return err 50 | } 51 | return nil 52 | }) 53 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/http_box_test.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "strings" 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func Test_HTTPBox(t *testing.T) { 13 | r := require.New(t) 14 | 15 | mux := http.NewServeMux() 16 | mux.Handle("/", http.FileServer(testBox)) 17 | 18 | req, err := http.NewRequest("GET", "/hello.txt", nil) 19 | r.NoError(err) 20 | 21 | res := httptest.NewRecorder() 22 | 23 | mux.ServeHTTP(res, req) 24 | 25 | r.Equal(200, res.Code) 26 | r.Equal("hello world!", strings.TrimSpace(res.Body.String())) 27 | } 28 | 29 | func Test_HTTPBox_NotFound(t *testing.T) { 30 | r := require.New(t) 31 | 32 | mux := http.NewServeMux() 33 | mux.Handle("/", http.FileServer(testBox)) 34 | 35 | req, err := http.NewRequest("GET", "/notInBox.txt", nil) 36 | r.NoError(err) 37 | 38 | res := httptest.NewRecorder() 39 | 40 | mux.ServeHTTP(res, req) 41 | 42 | r.Equal(404, res.Code) 43 | } 44 | 45 | func Test_HTTPBox_Handles_IndexHTML(t *testing.T) { 46 | r := require.New(t) 47 | 48 | mux := http.NewServeMux() 49 | mux.Handle("/", http.FileServer(testBox)) 50 | 51 | req, err := http.NewRequest("GET", "/", nil) 52 | r.NoError(err) 53 | 54 | res := httptest.NewRecorder() 55 | 56 | mux.ServeHTTP(res, req) 57 | 58 | r.Equal("

Index!

", strings.TrimSpace(res.Body.String())) 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/packr.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import ( 4 | "bytes" 5 | "compress/gzip" 6 | "encoding/json" 7 | "sync" 8 | ) 9 | 10 | var gil = &sync.Mutex{} 11 | var data = map[string]map[string][]byte{} 12 | 13 | // PackBytes packs bytes for a file into a box. 14 | func PackBytes(box string, name string, bb []byte) { 15 | gil.Lock() 16 | defer gil.Unlock() 17 | if _, ok := data[box]; !ok { 18 | data[box] = map[string][]byte{} 19 | } 20 | data[box][name] = bb 21 | } 22 | 23 | // PackBytesGzip packets the gzipped compressed bytes into a box. 24 | func PackBytesGzip(box string, name string, bb []byte) error { 25 | var buf bytes.Buffer 26 | w := gzip.NewWriter(&buf) 27 | _, err := w.Write(bb) 28 | if err != nil { 29 | return err 30 | } 31 | err = w.Close() 32 | if err != nil { 33 | return err 34 | } 35 | PackBytes(box, name, buf.Bytes()) 36 | return nil 37 | } 38 | 39 | // PackJSONBytes packs JSON encoded bytes for a file into a box. 40 | func PackJSONBytes(box string, name string, jbb string) error { 41 | bb := []byte{} 42 | err := json.Unmarshal([]byte(jbb), &bb) 43 | if err != nil { 44 | return err 45 | } 46 | PackBytes(box, name, bb) 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/packr/cmd/build.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "os" 6 | "os/exec" 7 | 8 | "github.com/gobuffalo/envy" 9 | "github.com/gobuffalo/packr/builder" 10 | "github.com/pkg/errors" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | // buildCmd represents the build command 15 | var buildCmd = &cobra.Command{ 16 | Use: "build", 17 | Short: "Wraps the go build command with packr", 18 | DisableFlagParsing: true, 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | defer builder.Clean(input) 21 | b := builder.New(context.Background(), input) 22 | err := b.Run() 23 | if err != nil { 24 | return errors.WithStack(err) 25 | } 26 | 27 | cargs := []string{"build"} 28 | cargs = append(cargs, args...) 29 | cp := exec.Command(envy.Get("GO_BIN", "go"), cargs...) 30 | cp.Stderr = os.Stderr 31 | cp.Stdin = os.Stdin 32 | cp.Stdout = os.Stdout 33 | 34 | return cp.Run() 35 | }, 36 | } 37 | 38 | func init() { 39 | rootCmd.AddCommand(buildCmd) 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/packr/cmd/clean.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/gobuffalo/packr/builder" 5 | "github.com/spf13/cobra" 6 | ) 7 | 8 | var cleanCmd = &cobra.Command{ 9 | Use: "clean", 10 | Short: "removes any *-packr.go files", 11 | Run: func(cmd *cobra.Command, args []string) { 12 | builder.Clean(input) 13 | }, 14 | } 15 | 16 | func init() { 17 | rootCmd.AddCommand(cleanCmd) 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/packr/cmd/install.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "os" 6 | "os/exec" 7 | "path/filepath" 8 | "strings" 9 | 10 | "github.com/gobuffalo/envy" 11 | "github.com/gobuffalo/packr/builder" 12 | "github.com/pkg/errors" 13 | "github.com/spf13/cobra" 14 | ) 15 | 16 | // installCmd represents the install command 17 | var installCmd = &cobra.Command{ 18 | Use: "install", 19 | Short: "Wraps the go install command with packr", 20 | DisableFlagParsing: true, 21 | RunE: func(cmd *cobra.Command, args []string) error { 22 | if len(args) > 0 { 23 | input = args[len(args)-1] 24 | if !strings.HasPrefix(input, ".") { 25 | input = filepath.Join(envy.GoPath(), "src", input) 26 | if _, err := os.Stat(input); err != nil { 27 | return errors.WithStack(err) 28 | } 29 | } 30 | } 31 | defer builder.Clean(input) 32 | b := builder.New(context.Background(), input) 33 | err := b.Run() 34 | if err != nil { 35 | return errors.WithStack(err) 36 | } 37 | 38 | cargs := []string{"install"} 39 | cargs = append(cargs, args...) 40 | cp := exec.Command(envy.Get("GO_BIN", "go"), cargs...) 41 | cp.Stderr = os.Stderr 42 | cp.Stdin = os.Stdin 43 | cp.Stdout = os.Stdout 44 | 45 | return cp.Run() 46 | }, 47 | } 48 | 49 | func init() { 50 | rootCmd.AddCommand(installCmd) 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/packr/cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "os" 6 | 7 | "github.com/gobuffalo/packr/builder" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | var input string 12 | var compress bool 13 | 14 | var rootCmd = &cobra.Command{ 15 | Use: "packr", 16 | Short: "compiles static files into Go files", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | b := builder.New(context.Background(), input) 19 | b.Compress = compress 20 | return b.Run() 21 | }, 22 | } 23 | 24 | func init() { 25 | pwd, _ := os.Getwd() 26 | rootCmd.Flags().StringVarP(&input, "input", "i", pwd, "path to scan for packr Boxes") 27 | rootCmd.Flags().BoolVarP(&compress, "compress", "z", false, "compress box contents") 28 | } 29 | 30 | // Execute the commands 31 | func Execute() { 32 | if err := rootCmd.Execute(); err != nil { 33 | os.Exit(-1) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/packr/main.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "github.com/gobuffalo/packr/packr/cmd" 18 | 19 | func main() { 20 | cmd.Execute() 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/packr_test.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import ( 4 | "encoding/json" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | var testBox = NewBox("./fixtures") 11 | var virtualBox = NewBox("./virtual") 12 | 13 | func init() { 14 | PackBytes(virtualBox.Path, "a", []byte("a")) 15 | PackBytes(virtualBox.Path, "b", []byte("b")) 16 | PackBytes(virtualBox.Path, "c", []byte("c")) 17 | PackBytes(virtualBox.Path, "d/a", []byte("d/a")) 18 | } 19 | 20 | func Test_PackBytes(t *testing.T) { 21 | r := require.New(t) 22 | PackBytes(testBox.Path, "foo", []byte("bar")) 23 | s := testBox.String("foo") 24 | r.Equal("bar", s) 25 | } 26 | 27 | func Test_PackJSONBytes(t *testing.T) { 28 | r := require.New(t) 29 | b, err := json.Marshal([]byte("json bytes")) 30 | r.NoError(err) 31 | err = PackJSONBytes(testBox.Path, "the bytes", string(b)) 32 | r.NoError(err) 33 | s, err := testBox.MustBytes("the bytes") 34 | r.NoError(err) 35 | r.Equal([]byte("json bytes"), s) 36 | } 37 | 38 | func Test_PackBytesGzip(t *testing.T) { 39 | r := require.New(t) 40 | err := PackBytesGzip(testBox.Path, "gzip", []byte("gzip foobar")) 41 | r.NoError(err) 42 | s := testBox.String("gzip") 43 | r.Equal("gzip foobar", s) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/physical_file.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import "os" 4 | 5 | var _ File = physicalFile{} 6 | 7 | type physicalFile struct { 8 | *os.File 9 | } 10 | 11 | func (p physicalFile) FileInfo() (os.FileInfo, error) { 12 | return os.Stat(p.Name()) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/gobuffalo/packr/virtual_file.go: -------------------------------------------------------------------------------- 1 | package packr 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os" 7 | "time" 8 | ) 9 | 10 | var virtualFileModTime = time.Now() 11 | var _ File = virtualFile{} 12 | 13 | type virtualFile struct { 14 | *bytes.Reader 15 | Name string 16 | info fileInfo 17 | } 18 | 19 | func (f virtualFile) FileInfo() (os.FileInfo, error) { 20 | return f.info, nil 21 | } 22 | 23 | func (f virtualFile) Close() error { 24 | return nil 25 | } 26 | 27 | func (f virtualFile) Write(p []byte) (n int, err error) { 28 | return 0, fmt.Errorf("Not implemented") 29 | } 30 | 31 | func (f virtualFile) Readdir(count int) ([]os.FileInfo, error) { 32 | return []os.FileInfo{f.info}, nil 33 | } 34 | 35 | func (f virtualFile) Stat() (os.FileInfo, error) { 36 | return f.info, nil 37 | } 38 | 39 | func newVirtualFile(name string, b []byte) File { 40 | return virtualFile{ 41 | Reader: bytes.NewReader(b), 42 | Name: name, 43 | info: fileInfo{ 44 | Path: name, 45 | Contents: b, 46 | size: int64(len(b)), 47 | modTime: virtualFileModTime, 48 | }, 49 | } 50 | } 51 | 52 | func newVirtualDir(name string) File { 53 | b := []byte{} 54 | v := newVirtualFile(name, b).(virtualFile) 55 | v.info.isDir = true 56 | return v 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/README.md: -------------------------------------------------------------------------------- 1 | # mousetrap 2 | 3 | mousetrap is a tiny library that answers a single question. 4 | 5 | On a Windows machine, was the process invoked by someone double clicking on 6 | the executable file while browsing in explorer? 7 | 8 | ### Motivation 9 | 10 | Windows developers unfamiliar with command line tools will often "double-click" 11 | the executable for a tool. Because most CLI tools print the help and then exit 12 | when invoked without arguments, this is often very frustrating for those users. 13 | 14 | mousetrap provides a way to detect these invocations so that you can provide 15 | more helpful behavior and instructions on how to run the CLI tool. To see what 16 | this looks like, both from an organizational and a technical perspective, see 17 | https://inconshreveable.com/09-09-2014/sweat-the-small-stuff/ 18 | 19 | ### The interface 20 | 21 | The library exposes a single interface: 22 | 23 | func StartedByExplorer() (bool) 24 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_others.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package mousetrap 4 | 5 | // StartedByExplorer returns true if the program was invoked by the user 6 | // double-clicking on the executable from explorer.exe 7 | // 8 | // It is conservative and returns false if any of the internal calls fail. 9 | // It does not guarantee that the program was run from a terminal. It only can tell you 10 | // whether it was launched from explorer.exe 11 | // 12 | // On non-Windows platforms, it always returns false. 13 | func StartedByExplorer() bool { 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build !go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | const ( 14 | // defined by the Win32 API 15 | th32cs_snapprocess uintptr = 0x2 16 | ) 17 | 18 | var ( 19 | kernel = syscall.MustLoadDLL("kernel32.dll") 20 | CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot") 21 | Process32First = kernel.MustFindProc("Process32FirstW") 22 | Process32Next = kernel.MustFindProc("Process32NextW") 23 | ) 24 | 25 | // ProcessEntry32 structure defined by the Win32 API 26 | type processEntry32 struct { 27 | dwSize uint32 28 | cntUsage uint32 29 | th32ProcessID uint32 30 | th32DefaultHeapID int 31 | th32ModuleID uint32 32 | cntThreads uint32 33 | th32ParentProcessID uint32 34 | pcPriClassBase int32 35 | dwFlags uint32 36 | szExeFile [syscall.MAX_PATH]uint16 37 | } 38 | 39 | func getProcessEntry(pid int) (pe *processEntry32, err error) { 40 | snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0)) 41 | if snapshot == uintptr(syscall.InvalidHandle) { 42 | err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1) 43 | return 44 | } 45 | defer syscall.CloseHandle(syscall.Handle(snapshot)) 46 | 47 | var processEntry processEntry32 48 | processEntry.dwSize = uint32(unsafe.Sizeof(processEntry)) 49 | ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 50 | if ok == 0 { 51 | err = fmt.Errorf("Process32First: %v", e1) 52 | return 53 | } 54 | 55 | for { 56 | if processEntry.th32ProcessID == uint32(pid) { 57 | pe = &processEntry 58 | return 59 | } 60 | 61 | ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 62 | if ok == 0 { 63 | err = fmt.Errorf("Process32Next: %v", e1) 64 | return 65 | } 66 | } 67 | } 68 | 69 | func getppid() (pid int, err error) { 70 | pe, err := getProcessEntry(os.Getpid()) 71 | if err != nil { 72 | return 73 | } 74 | 75 | pid = int(pe.th32ParentProcessID) 76 | return 77 | } 78 | 79 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 80 | // on the executable from explorer.exe 81 | // 82 | // It is conservative and returns false if any of the internal calls fail. 83 | // It does not guarantee that the program was run from a terminal. It only can tell you 84 | // whether it was launched from explorer.exe 85 | func StartedByExplorer() bool { 86 | ppid, err := getppid() 87 | if err != nil { 88 | return false 89 | } 90 | 91 | pe, err := getProcessEntry(ppid) 92 | if err != nil { 93 | return false 94 | } 95 | 96 | name := syscall.UTF16ToString(pe.szExeFile[:]) 97 | return name == "explorer.exe" 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { 13 | snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) 14 | if err != nil { 15 | return nil, err 16 | } 17 | defer syscall.CloseHandle(snapshot) 18 | var procEntry syscall.ProcessEntry32 19 | procEntry.Size = uint32(unsafe.Sizeof(procEntry)) 20 | if err = syscall.Process32First(snapshot, &procEntry); err != nil { 21 | return nil, err 22 | } 23 | for { 24 | if procEntry.ProcessID == uint32(pid) { 25 | return &procEntry, nil 26 | } 27 | err = syscall.Process32Next(snapshot, &procEntry) 28 | if err != nil { 29 | return nil, err 30 | } 31 | } 32 | } 33 | 34 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 35 | // on the executable from explorer.exe 36 | // 37 | // It is conservative and returns false if any of the internal calls fail. 38 | // It does not guarantee that the program was run from a terminal. It only can tell you 39 | // whether it was launched from explorer.exe 40 | func StartedByExplorer() bool { 41 | pe, err := getProcessEntry(os.Getppid()) 42 | if err != nil { 43 | return false 44 | } 45 | return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.8 5 | 6 | os: 7 | - linux 8 | - osx 9 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 John Barton 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/autoload/autoload.go: -------------------------------------------------------------------------------- 1 | package autoload 2 | 3 | /* 4 | You can just read the .env file on import just by doing 5 | 6 | import _ "github.com/joho/godotenv/autoload" 7 | 8 | And bob's your mother's brother 9 | */ 10 | 11 | import "github.com/joho/godotenv" 12 | 13 | func init() { 14 | godotenv.Load() 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/cmd/godotenv/cmd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "log" 7 | 8 | "strings" 9 | 10 | "github.com/joho/godotenv" 11 | ) 12 | 13 | func main() { 14 | var showHelp bool 15 | flag.BoolVar(&showHelp, "h", false, "show help") 16 | var rawEnvFilenames string 17 | flag.StringVar(&rawEnvFilenames, "f", "", "comma separated paths to .env files") 18 | 19 | flag.Parse() 20 | 21 | usage := ` 22 | Run a process with a env setup from a .env file 23 | 24 | godotenv [-f ENV_FILE_PATHS] COMMAND_ARGS 25 | 26 | ENV_FILE_PATHS: comma separated paths to .env files 27 | COMMAND_ARGS: command and args you want to run 28 | 29 | example 30 | godotenv -f /path/to/something/.env,/another/path/.env fortune 31 | ` 32 | // if no args or -h flag 33 | // print usage and return 34 | args := flag.Args() 35 | if showHelp || len(args) == 0 { 36 | fmt.Println(usage) 37 | return 38 | } 39 | 40 | // load env 41 | var envFilenames []string 42 | if rawEnvFilenames != "" { 43 | envFilenames = strings.Split(rawEnvFilenames, ",") 44 | } 45 | 46 | // take rest of args and "exec" them 47 | cmd := args[0] 48 | cmdArgs := args[1:] 49 | 50 | err := godotenv.Exec(envFilenames, cmd, cmdArgs) 51 | if err != nil { 52 | log.Fatal(err) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/fixtures/equals.env: -------------------------------------------------------------------------------- 1 | export OPTION_A='postgres://localhost:5432/database?sslmode=disable' 2 | 3 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/fixtures/exported.env: -------------------------------------------------------------------------------- 1 | export OPTION_A=2 2 | export OPTION_B='\n' 3 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/fixtures/invalid1.env: -------------------------------------------------------------------------------- 1 | INVALID LINE 2 | foo=bar 3 | -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/fixtures/plain.env: -------------------------------------------------------------------------------- 1 | OPTION_A=1 2 | OPTION_B=2 3 | OPTION_C= 3 4 | OPTION_D =4 5 | OPTION_E = 5 6 | OPTION_F = 7 | OPTION_G= -------------------------------------------------------------------------------- /vendor/github.com/joho/godotenv/fixtures/quoted.env: -------------------------------------------------------------------------------- 1 | OPTION_A='1' 2 | OPTION_B='2' 3 | OPTION_C='' 4 | OPTION_D='\n' 5 | OPTION_E="1" 6 | OPTION_F="2" 7 | OPTION_G="" 8 | OPTION_H="\n" 9 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/go-homedir/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Mitchell Hashimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/go-homedir/README.md: -------------------------------------------------------------------------------- 1 | # go-homedir 2 | 3 | This is a Go library for detecting the user's home directory without 4 | the use of cgo, so the library can be used in cross-compilation environments. 5 | 6 | Usage is incredibly simple, just call `homedir.Dir()` to get the home directory 7 | for a user, and `homedir.Expand()` to expand the `~` in a path to the home 8 | directory. 9 | 10 | **Why not just use `os/user`?** The built-in `os/user` package requires 11 | cgo on Darwin systems. This means that any Go code that uses that package 12 | cannot cross compile. But 99% of the time the use for `os/user` is just to 13 | retrieve the home directory, which we can do for the current user without 14 | cgo. This library does that, enabling cross-compilation. 15 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/go-homedir/homedir.go: -------------------------------------------------------------------------------- 1 | package homedir 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "os" 7 | "os/exec" 8 | "path/filepath" 9 | "runtime" 10 | "strconv" 11 | "strings" 12 | "sync" 13 | ) 14 | 15 | // DisableCache will disable caching of the home directory. Caching is enabled 16 | // by default. 17 | var DisableCache bool 18 | 19 | var homedirCache string 20 | var cacheLock sync.RWMutex 21 | 22 | // Dir returns the home directory for the executing user. 23 | // 24 | // This uses an OS-specific method for discovering the home directory. 25 | // An error is returned if a home directory cannot be detected. 26 | func Dir() (string, error) { 27 | if !DisableCache { 28 | cacheLock.RLock() 29 | cached := homedirCache 30 | cacheLock.RUnlock() 31 | if cached != "" { 32 | return cached, nil 33 | } 34 | } 35 | 36 | cacheLock.Lock() 37 | defer cacheLock.Unlock() 38 | 39 | var result string 40 | var err error 41 | if runtime.GOOS == "windows" { 42 | result, err = dirWindows() 43 | } else { 44 | // Unix-like system, so just assume Unix 45 | result, err = dirUnix() 46 | } 47 | 48 | if err != nil { 49 | return "", err 50 | } 51 | homedirCache = result 52 | return result, nil 53 | } 54 | 55 | // Expand expands the path to include the home directory if the path 56 | // is prefixed with `~`. If it isn't prefixed with `~`, the path is 57 | // returned as-is. 58 | func Expand(path string) (string, error) { 59 | if len(path) == 0 { 60 | return path, nil 61 | } 62 | 63 | if path[0] != '~' { 64 | return path, nil 65 | } 66 | 67 | if len(path) > 1 && path[1] != '/' && path[1] != '\\' { 68 | return "", errors.New("cannot expand user-specific home dir") 69 | } 70 | 71 | dir, err := Dir() 72 | if err != nil { 73 | return "", err 74 | } 75 | 76 | return filepath.Join(dir, path[1:]), nil 77 | } 78 | 79 | func dirUnix() (string, error) { 80 | // First prefer the HOME environmental variable 81 | if home := os.Getenv("HOME"); home != "" { 82 | return home, nil 83 | } 84 | 85 | // If that fails, try getent 86 | var stdout bytes.Buffer 87 | cmd := exec.Command("getent", "passwd", strconv.Itoa(os.Getuid())) 88 | cmd.Stdout = &stdout 89 | if err := cmd.Run(); err != nil { 90 | // If the error is ErrNotFound, we ignore it. Otherwise, return it. 91 | if err != exec.ErrNotFound { 92 | return "", err 93 | } 94 | } else { 95 | if passwd := strings.TrimSpace(stdout.String()); passwd != "" { 96 | // username:password:uid:gid:gecos:home:shell 97 | passwdParts := strings.SplitN(passwd, ":", 7) 98 | if len(passwdParts) > 5 { 99 | return passwdParts[5], nil 100 | } 101 | } 102 | } 103 | 104 | // If all else fails, try the shell 105 | stdout.Reset() 106 | cmd = exec.Command("sh", "-c", "cd && pwd") 107 | cmd.Stdout = &stdout 108 | if err := cmd.Run(); err != nil { 109 | return "", err 110 | } 111 | 112 | result := strings.TrimSpace(stdout.String()) 113 | if result == "" { 114 | return "", errors.New("blank output when reading home directory") 115 | } 116 | 117 | return result, nil 118 | } 119 | 120 | func dirWindows() (string, error) { 121 | // First prefer the HOME environmental variable 122 | if home := os.Getenv("HOME"); home != "" { 123 | return home, nil 124 | } 125 | 126 | drive := os.Getenv("HOMEDRIVE") 127 | path := os.Getenv("HOMEPATH") 128 | home := drive + path 129 | if drive == "" || path == "" { 130 | home = os.Getenv("USERPROFILE") 131 | } 132 | if home == "" { 133 | return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank") 134 | } 135 | 136 | return home, nil 137 | } 138 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/go-homedir/homedir_test.go: -------------------------------------------------------------------------------- 1 | package homedir 2 | 3 | import ( 4 | "os" 5 | "os/user" 6 | "path/filepath" 7 | "testing" 8 | ) 9 | 10 | func patchEnv(key, value string) func() { 11 | bck := os.Getenv(key) 12 | deferFunc := func() { 13 | os.Setenv(key, bck) 14 | } 15 | 16 | os.Setenv(key, value) 17 | return deferFunc 18 | } 19 | 20 | func BenchmarkDir(b *testing.B) { 21 | // We do this for any "warmups" 22 | for i := 0; i < 10; i++ { 23 | Dir() 24 | } 25 | 26 | b.ResetTimer() 27 | for i := 0; i < b.N; i++ { 28 | Dir() 29 | } 30 | } 31 | 32 | func TestDir(t *testing.T) { 33 | u, err := user.Current() 34 | if err != nil { 35 | t.Fatalf("err: %s", err) 36 | } 37 | 38 | dir, err := Dir() 39 | if err != nil { 40 | t.Fatalf("err: %s", err) 41 | } 42 | 43 | if u.HomeDir != dir { 44 | t.Fatalf("%#v != %#v", u.HomeDir, dir) 45 | } 46 | } 47 | 48 | func TestExpand(t *testing.T) { 49 | u, err := user.Current() 50 | if err != nil { 51 | t.Fatalf("err: %s", err) 52 | } 53 | 54 | cases := []struct { 55 | Input string 56 | Output string 57 | Err bool 58 | }{ 59 | { 60 | "/foo", 61 | "/foo", 62 | false, 63 | }, 64 | 65 | { 66 | "~/foo", 67 | filepath.Join(u.HomeDir, "foo"), 68 | false, 69 | }, 70 | 71 | { 72 | "", 73 | "", 74 | false, 75 | }, 76 | 77 | { 78 | "~", 79 | u.HomeDir, 80 | false, 81 | }, 82 | 83 | { 84 | "~foo/foo", 85 | "", 86 | true, 87 | }, 88 | } 89 | 90 | for _, tc := range cases { 91 | actual, err := Expand(tc.Input) 92 | if (err != nil) != tc.Err { 93 | t.Fatalf("Input: %#v\n\nErr: %s", tc.Input, err) 94 | } 95 | 96 | if actual != tc.Output { 97 | t.Fatalf("Input: %#v\n\nOutput: %#v", tc.Input, actual) 98 | } 99 | } 100 | 101 | DisableCache = true 102 | defer func() { DisableCache = false }() 103 | defer patchEnv("HOME", "/custom/path/")() 104 | expected := filepath.Join("/", "custom", "path", "foo/bar") 105 | actual, err := Expand("~/foo/bar") 106 | 107 | if err != nil { 108 | t.Errorf("No error is expected, got: %v", err) 109 | } else if actual != expected { 110 | t.Errorf("Expected: %v; actual: %v", expected, actual) 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/pkg/errors 3 | go: 4 | - 1.4.3 5 | - 1.5.4 6 | - 1.6.2 7 | - 1.7.1 8 | - tip 9 | 10 | script: 11 | - go test -v ./... 12 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Dave Cheney 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/README.md: -------------------------------------------------------------------------------- 1 | # errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) 2 | 3 | Package errors provides simple error handling primitives. 4 | 5 | `go get github.com/pkg/errors` 6 | 7 | The traditional error handling idiom in Go is roughly akin to 8 | ```go 9 | if err != nil { 10 | return err 11 | } 12 | ``` 13 | which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error. 14 | 15 | ## Adding context to an error 16 | 17 | The errors.Wrap function returns a new error that adds context to the original error. For example 18 | ```go 19 | _, err := ioutil.ReadAll(r) 20 | if err != nil { 21 | return errors.Wrap(err, "read failed") 22 | } 23 | ``` 24 | ## Retrieving the cause of an error 25 | 26 | Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`. 27 | ```go 28 | type causer interface { 29 | Cause() error 30 | } 31 | ``` 32 | `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example: 33 | ```go 34 | switch err := errors.Cause(err).(type) { 35 | case *MyError: 36 | // handle specifically 37 | default: 38 | // unknown error 39 | } 40 | ``` 41 | 42 | [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). 43 | 44 | ## Contributing 45 | 46 | We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high. 47 | 48 | Before proposing a change, please discuss your change by raising an issue. 49 | 50 | ## Licence 51 | 52 | BSD-2-Clause 53 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: build-{build}.{branch} 2 | 3 | clone_folder: C:\gopath\src\github.com\pkg\errors 4 | shallow_clone: true # for startup speed 5 | 6 | environment: 7 | GOPATH: C:\gopath 8 | 9 | platform: 10 | - x64 11 | 12 | # http://www.appveyor.com/docs/installed-software 13 | install: 14 | # some helpful output for debugging builds 15 | - go version 16 | - go env 17 | # pre-installed MinGW at C:\MinGW is 32bit only 18 | # but MSYS2 at C:\msys64 has mingw64 19 | - set PATH=C:\msys64\mingw64\bin;%PATH% 20 | - gcc --version 21 | - g++ --version 22 | 23 | build_script: 24 | - go install -v ./... 25 | 26 | test_script: 27 | - set PATH=C:\gopath\bin;%PATH% 28 | - go test -v ./... 29 | 30 | #artifacts: 31 | # - path: '%GOPATH%\bin\*.exe' 32 | deploy: off 33 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/bench_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package errors 4 | 5 | import ( 6 | "fmt" 7 | "testing" 8 | 9 | stderrors "errors" 10 | ) 11 | 12 | func noErrors(at, depth int) error { 13 | if at >= depth { 14 | return stderrors.New("no error") 15 | } 16 | return noErrors(at+1, depth) 17 | } 18 | func yesErrors(at, depth int) error { 19 | if at >= depth { 20 | return New("ye error") 21 | } 22 | return yesErrors(at+1, depth) 23 | } 24 | 25 | func BenchmarkErrors(b *testing.B) { 26 | var toperr error 27 | type run struct { 28 | stack int 29 | std bool 30 | } 31 | runs := []run{ 32 | {10, false}, 33 | {10, true}, 34 | {100, false}, 35 | {100, true}, 36 | {1000, false}, 37 | {1000, true}, 38 | } 39 | for _, r := range runs { 40 | part := "pkg/errors" 41 | if r.std { 42 | part = "errors" 43 | } 44 | name := fmt.Sprintf("%s-stack-%d", part, r.stack) 45 | b.Run(name, func(b *testing.B) { 46 | var err error 47 | f := yesErrors 48 | if r.std { 49 | f = noErrors 50 | } 51 | b.ReportAllocs() 52 | for i := 0; i < b.N; i++ { 53 | err = f(0, r.stack) 54 | } 55 | b.StopTimer() 56 | toperr = err 57 | }) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | # Vim files https://github.com/github/gitignore/blob/master/Global/Vim.gitignore 23 | # swap 24 | [._]*.s[a-w][a-z] 25 | [._]s[a-w][a-z] 26 | # session 27 | Session.vim 28 | # temporary 29 | .netrwhist 30 | *~ 31 | # auto-generated tag files 32 | tags 33 | 34 | *.exe 35 | 36 | cobra.test 37 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.mailmap: -------------------------------------------------------------------------------- 1 | Steve Francia 2 | Bjørn Erik Pedersen 3 | Fabiano Franz 4 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | matrix: 4 | include: 5 | - go: 1.7.6 6 | - go: 1.8.3 7 | - go: tip 8 | allow_failures: 9 | - go: tip 10 | 11 | before_install: 12 | - mkdir -p bin 13 | - curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.3/shellcheck 14 | - chmod +x bin/shellcheck 15 | script: 16 | - PATH=$PATH:$PWD/bin go test -v ./... 17 | - go build 18 | - diff -u <(echo -n) <(gofmt -d -s .) 19 | - if [ -z $NOVET ]; then 20 | diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint'); 21 | fi 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/args.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type PositionalArgs func(cmd *Command, args []string) error 8 | 9 | // Legacy arg validation has the following behaviour: 10 | // - root commands with no subcommands can take arbitrary arguments 11 | // - root commands with subcommands will do subcommand validity checking 12 | // - subcommands will always accept arbitrary arguments 13 | func legacyArgs(cmd *Command, args []string) error { 14 | // no subcommand, always take args 15 | if !cmd.HasSubCommands() { 16 | return nil 17 | } 18 | 19 | // root command with subcommands, do subcommand checking 20 | if !cmd.HasParent() && len(args) > 0 { 21 | return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0])) 22 | } 23 | return nil 24 | } 25 | 26 | // NoArgs returns an error if any args are included 27 | func NoArgs(cmd *Command, args []string) error { 28 | if len(args) > 0 { 29 | return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath()) 30 | } 31 | return nil 32 | } 33 | 34 | // OnlyValidArgs returns an error if any args are not in the list of ValidArgs 35 | func OnlyValidArgs(cmd *Command, args []string) error { 36 | if len(cmd.ValidArgs) > 0 { 37 | for _, v := range args { 38 | if !stringInSlice(v, cmd.ValidArgs) { 39 | return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0])) 40 | } 41 | } 42 | } 43 | return nil 44 | } 45 | 46 | func stringInSlice(a string, list []string) bool { 47 | for _, b := range list { 48 | if b == a { 49 | return true 50 | } 51 | } 52 | return false 53 | } 54 | 55 | // ArbitraryArgs never returns an error 56 | func ArbitraryArgs(cmd *Command, args []string) error { 57 | return nil 58 | } 59 | 60 | // MinimumNArgs returns an error if there is not at least N args 61 | func MinimumNArgs(n int) PositionalArgs { 62 | return func(cmd *Command, args []string) error { 63 | if len(args) < n { 64 | return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args)) 65 | } 66 | return nil 67 | } 68 | } 69 | 70 | // MaximumNArgs returns an error if there are more than N args 71 | func MaximumNArgs(n int) PositionalArgs { 72 | return func(cmd *Command, args []string) error { 73 | if len(args) > n { 74 | return fmt.Errorf("accepts at most %d arg(s), received %d", n, len(args)) 75 | } 76 | return nil 77 | } 78 | } 79 | 80 | // ExactArgs returns an error if there are not exactly n args 81 | func ExactArgs(n int) PositionalArgs { 82 | return func(cmd *Command, args []string) error { 83 | if len(args) != n { 84 | return fmt.Errorf("accepts %d arg(s), received %d", n, len(args)) 85 | } 86 | return nil 87 | } 88 | } 89 | 90 | // RangeArgs returns an error if the number of args is not within the expected range 91 | func RangeArgs(min int, max int) PositionalArgs { 92 | return func(cmd *Command, args []string) error { 93 | if len(args) < min || len(args) > max { 94 | return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args)) 95 | } 96 | return nil 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/README.md: -------------------------------------------------------------------------------- 1 | # Cobra Generator 2 | 3 | Cobra provides its own program that will create your application and add any 4 | commands you want. It's the easiest way to incorporate Cobra into your application. 5 | 6 | In order to use the cobra command, compile it using the following command: 7 | 8 | go get github.com/spf13/cobra/cobra 9 | 10 | This will create the cobra executable under your `$GOPATH/bin` directory. 11 | 12 | ### cobra init 13 | 14 | The `cobra init [app]` command will create your initial application code 15 | for you. It is a very powerful application that will populate your program with 16 | the right structure so you can immediately enjoy all the benefits of Cobra. It 17 | will also automatically apply the license you specify to your application. 18 | 19 | Cobra init is pretty smart. You can provide it a full path, or simply a path 20 | similar to what is expected in the import. 21 | 22 | ``` 23 | cobra init github.com/spf13/newApp 24 | ``` 25 | 26 | ### cobra add 27 | 28 | Once an application is initialized, Cobra can create additional commands for you. 29 | Let's say you created an app and you wanted the following commands for it: 30 | 31 | * app serve 32 | * app config 33 | * app config create 34 | 35 | In your project directory (where your main.go file is) you would run the following: 36 | 37 | ``` 38 | cobra add serve 39 | cobra add config 40 | cobra add create -p 'configCmd' 41 | ``` 42 | 43 | *Note: Use camelCase (not snake_case/snake-case) for command names. 44 | Otherwise, you will encounter errors. 45 | For example, `cobra add add-user` is incorrect, but `cobra add addUser` is valid.* 46 | 47 | Once you have run these three commands you would have an app structure similar to 48 | the following: 49 | 50 | ``` 51 | ▾ app/ 52 | ▾ cmd/ 53 | serve.go 54 | config.go 55 | create.go 56 | main.go 57 | ``` 58 | 59 | At this point you can run `go run main.go` and it would run your app. `go run 60 | main.go serve`, `go run main.go config`, `go run main.go config create` along 61 | with `go run main.go help serve`, etc. would all work. 62 | 63 | Obviously you haven't added your own code to these yet. The commands are ready 64 | for you to give them their tasks. Have fun! 65 | 66 | ### Configuring the cobra generator 67 | 68 | The Cobra generator will be easier to use if you provide a simple configuration 69 | file which will help you eliminate providing a bunch of repeated information in 70 | flags over and over. 71 | 72 | An example ~/.cobra.yaml file: 73 | 74 | ```yaml 75 | author: Steve Francia 76 | license: MIT 77 | ``` 78 | 79 | You can specify no license by setting `license` to `none` or you can specify 80 | a custom license: 81 | 82 | ```yaml 83 | license: 84 | header: This file is part of {{ .appName }}. 85 | text: | 86 | {{ .copyright }} 87 | 88 | This is my license. There are many like it, but this one is mine. 89 | My license is my best friend. It is my life. I must master it as I must 90 | master my life. 91 | ``` 92 | 93 | You can also use built-in licenses. For example, **GPLv2**, **GPLv3**, **LGPL**, 94 | **AGPL**, **MIT**, **2-Clause BSD** or **3-Clause BSD**. 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/add_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "errors" 5 | "io/ioutil" 6 | "os" 7 | "path/filepath" 8 | "testing" 9 | 10 | "github.com/spf13/viper" 11 | ) 12 | 13 | // TestGoldenAddCmd initializes the project "github.com/spf13/testproject" 14 | // in GOPATH, adds "test" command 15 | // and compares the content of all files in cmd directory of testproject 16 | // with appropriate golden files. 17 | // Use -update to update existing golden files. 18 | func TestGoldenAddCmd(t *testing.T) { 19 | projectName := "github.com/spf13/testproject" 20 | project := NewProject(projectName) 21 | defer os.RemoveAll(project.AbsPath()) 22 | 23 | viper.Set("author", "NAME HERE ") 24 | viper.Set("license", "apache") 25 | viper.Set("year", 2017) 26 | defer viper.Set("author", nil) 27 | defer viper.Set("license", nil) 28 | defer viper.Set("year", nil) 29 | 30 | // Initialize the project first. 31 | initializeProject(project) 32 | 33 | // Then add the "test" command. 34 | cmdName := "test" 35 | cmdPath := filepath.Join(project.CmdPath(), cmdName+".go") 36 | createCmdFile(project.License(), cmdPath, cmdName) 37 | 38 | expectedFiles := []string{".", "root.go", "test.go"} 39 | gotFiles := []string{} 40 | 41 | // Check project file hierarchy and compare the content of every single file 42 | // with appropriate golden file. 43 | err := filepath.Walk(project.CmdPath(), func(path string, info os.FileInfo, err error) error { 44 | if err != nil { 45 | return err 46 | } 47 | 48 | // Make path relative to project.CmdPath(). 49 | // E.g. path = "/home/user/go/src/github.com/spf13/testproject/cmd/root.go" 50 | // then it returns just "root.go". 51 | relPath, err := filepath.Rel(project.CmdPath(), path) 52 | if err != nil { 53 | return err 54 | } 55 | relPath = filepath.ToSlash(relPath) 56 | gotFiles = append(gotFiles, relPath) 57 | goldenPath := filepath.Join("testdata", filepath.Base(path)+".golden") 58 | 59 | switch relPath { 60 | // Known directories. 61 | case ".": 62 | return nil 63 | // Known files. 64 | case "root.go", "test.go": 65 | if *update { 66 | got, err := ioutil.ReadFile(path) 67 | if err != nil { 68 | return err 69 | } 70 | ioutil.WriteFile(goldenPath, got, 0644) 71 | } 72 | return compareFiles(path, goldenPath) 73 | } 74 | // Unknown file. 75 | return errors.New("unknown file: " + path) 76 | }) 77 | if err != nil { 78 | t.Fatal(err) 79 | } 80 | 81 | // Check if some files lack. 82 | if err := checkLackFiles(expectedFiles, gotFiles); err != nil { 83 | t.Fatal(err) 84 | } 85 | } 86 | 87 | func TestValidateCmdName(t *testing.T) { 88 | testCases := []struct { 89 | input string 90 | expected string 91 | }{ 92 | {"cmdName", "cmdName"}, 93 | {"cmd_name", "cmdName"}, 94 | {"cmd-name", "cmdName"}, 95 | {"cmd______Name", "cmdName"}, 96 | {"cmd------Name", "cmdName"}, 97 | {"cmd______name", "cmdName"}, 98 | {"cmd------name", "cmdName"}, 99 | {"cmdName-----", "cmdName"}, 100 | {"cmdname-", "cmdname"}, 101 | } 102 | 103 | for _, testCase := range testCases { 104 | got := validateCmdName(testCase.input) 105 | if testCase.expected != got { 106 | t.Errorf("Expected %q, got %q", testCase.expected, got) 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/golden_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "flag" 7 | "fmt" 8 | "io/ioutil" 9 | "os/exec" 10 | ) 11 | 12 | var update = flag.Bool("update", false, "update .golden files") 13 | 14 | func init() { 15 | // Mute commands. 16 | addCmd.SetOutput(new(bytes.Buffer)) 17 | initCmd.SetOutput(new(bytes.Buffer)) 18 | } 19 | 20 | // compareFiles compares the content of files with pathA and pathB. 21 | // If contents are equal, it returns nil. 22 | // If not, it returns which files are not equal 23 | // and diff (if system has diff command) between these files. 24 | func compareFiles(pathA, pathB string) error { 25 | contentA, err := ioutil.ReadFile(pathA) 26 | if err != nil { 27 | return err 28 | } 29 | contentB, err := ioutil.ReadFile(pathB) 30 | if err != nil { 31 | return err 32 | } 33 | if !bytes.Equal(contentA, contentB) { 34 | output := new(bytes.Buffer) 35 | output.WriteString(fmt.Sprintf("%q and %q are not equal!\n\n", pathA, pathB)) 36 | 37 | diffPath, err := exec.LookPath("diff") 38 | if err != nil { 39 | // Don't execute diff if it can't be found. 40 | return nil 41 | } 42 | diffCmd := exec.Command(diffPath, "-u", pathA, pathB) 43 | diffCmd.Stdout = output 44 | diffCmd.Stderr = output 45 | 46 | output.WriteString("$ diff -u " + pathA + " " + pathB + "\n") 47 | if err := diffCmd.Run(); err != nil { 48 | output.WriteString("\n" + err.Error()) 49 | } 50 | return errors.New(output.String()) 51 | } 52 | return nil 53 | } 54 | 55 | // checkLackFiles checks if all elements of expected are in got. 56 | func checkLackFiles(expected, got []string) error { 57 | lacks := make([]string, 0, len(expected)) 58 | for _, ev := range expected { 59 | if !stringInStringSlice(ev, got) { 60 | lacks = append(lacks, ev) 61 | } 62 | } 63 | if len(lacks) > 0 { 64 | return fmt.Errorf("Lack %v file(s): %v", len(lacks), lacks) 65 | } 66 | return nil 67 | } 68 | 69 | // stringInStringSlice checks if s is an element of slice. 70 | func stringInStringSlice(s string, slice []string) bool { 71 | for _, v := range slice { 72 | if s == v { 73 | return true 74 | } 75 | } 76 | return false 77 | } 78 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/init_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "errors" 5 | "io/ioutil" 6 | "os" 7 | "path/filepath" 8 | "testing" 9 | 10 | "github.com/spf13/viper" 11 | ) 12 | 13 | // TestGoldenInitCmd initializes the project "github.com/spf13/testproject" 14 | // in GOPATH and compares the content of files in initialized project with 15 | // appropriate golden files ("testdata/*.golden"). 16 | // Use -update to update existing golden files. 17 | func TestGoldenInitCmd(t *testing.T) { 18 | projectName := "github.com/spf13/testproject" 19 | project := NewProject(projectName) 20 | defer os.RemoveAll(project.AbsPath()) 21 | 22 | viper.Set("author", "NAME HERE ") 23 | viper.Set("license", "apache") 24 | viper.Set("year", 2017) 25 | defer viper.Set("author", nil) 26 | defer viper.Set("license", nil) 27 | defer viper.Set("year", nil) 28 | 29 | os.Args = []string{"cobra", "init", projectName} 30 | if err := rootCmd.Execute(); err != nil { 31 | t.Fatal("Error by execution:", err) 32 | } 33 | 34 | expectedFiles := []string{".", "cmd", "LICENSE", "main.go", "cmd/root.go"} 35 | gotFiles := []string{} 36 | 37 | // Check project file hierarchy and compare the content of every single file 38 | // with appropriate golden file. 39 | err := filepath.Walk(project.AbsPath(), func(path string, info os.FileInfo, err error) error { 40 | if err != nil { 41 | return err 42 | } 43 | 44 | // Make path relative to project.AbsPath(). 45 | // E.g. path = "/home/user/go/src/github.com/spf13/testproject/cmd/root.go" 46 | // then it returns just "cmd/root.go". 47 | relPath, err := filepath.Rel(project.AbsPath(), path) 48 | if err != nil { 49 | return err 50 | } 51 | relPath = filepath.ToSlash(relPath) 52 | gotFiles = append(gotFiles, relPath) 53 | goldenPath := filepath.Join("testdata", filepath.Base(path)+".golden") 54 | 55 | switch relPath { 56 | // Known directories. 57 | case ".", "cmd": 58 | return nil 59 | // Known files. 60 | case "LICENSE", "main.go", "cmd/root.go": 61 | if *update { 62 | got, err := ioutil.ReadFile(path) 63 | if err != nil { 64 | return err 65 | } 66 | if err := ioutil.WriteFile(goldenPath, got, 0644); err != nil { 67 | t.Fatal("Error while updating file:", err) 68 | } 69 | } 70 | return compareFiles(path, goldenPath) 71 | } 72 | // Unknown file. 73 | return errors.New("unknown file: " + path) 74 | }) 75 | if err != nil { 76 | t.Fatal(err) 77 | } 78 | 79 | // Check if some files lack. 80 | if err := checkLackFiles(expectedFiles, gotFiles); err != nil { 81 | t.Fatal(err) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/license_mit.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Steve Francia . 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Parts inspired by https://github.com/ryanuber/go-license 15 | 16 | package cmd 17 | 18 | func initMit() { 19 | Licenses["mit"] = License{ 20 | Name: "MIT License", 21 | PossibleMatches: []string{"mit"}, 22 | Header: ` 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 38 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 39 | THE SOFTWARE.`, 40 | Text: `The MIT License (MIT) 41 | 42 | {{ .copyright }} 43 | 44 | Permission is hereby granted, free of charge, to any person obtaining a copy 45 | of this software and associated documentation files (the "Software"), to deal 46 | in the Software without restriction, including without limitation the rights 47 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 48 | copies of the Software, and to permit persons to whom the Software is 49 | furnished to do so, subject to the following conditions: 50 | 51 | The above copyright notice and this permission notice shall be included in 52 | all copies or substantial portions of the Software. 53 | 54 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 55 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 56 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 57 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 59 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 60 | THE SOFTWARE. 61 | `, 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/project_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestFindExistingPackage(t *testing.T) { 8 | path := findPackage("github.com/spf13/cobra") 9 | if path == "" { 10 | t.Fatal("findPackage didn't find the existing package") 11 | } 12 | if !hasGoPathPrefix(path) { 13 | t.Fatalf("%q is not in GOPATH, but must be", path) 14 | } 15 | } 16 | 17 | func hasGoPathPrefix(path string) bool { 18 | for _, srcPath := range srcPaths { 19 | if filepathHasPrefix(path, srcPath) { 20 | return true 21 | } 22 | } 23 | return false 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/root.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Steve Francia . 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package cmd 15 | 16 | import ( 17 | "fmt" 18 | 19 | homedir "github.com/mitchellh/go-homedir" 20 | "github.com/spf13/cobra" 21 | "github.com/spf13/viper" 22 | ) 23 | 24 | var ( 25 | // Used for flags. 26 | cfgFile, userLicense string 27 | 28 | rootCmd = &cobra.Command{ 29 | Use: "cobra", 30 | Short: "A generator for Cobra based Applications", 31 | Long: `Cobra is a CLI library for Go that empowers applications. 32 | This application is a tool to generate the needed files 33 | to quickly create a Cobra application.`, 34 | } 35 | ) 36 | 37 | // Execute executes the root command. 38 | func Execute() { 39 | rootCmd.Execute() 40 | } 41 | 42 | func init() { 43 | cobra.OnInitialize(initConfig) 44 | 45 | rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") 46 | rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution") 47 | rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project") 48 | rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration") 49 | viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author")) 50 | viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper")) 51 | viper.SetDefault("author", "NAME HERE ") 52 | viper.SetDefault("license", "apache") 53 | 54 | rootCmd.AddCommand(addCmd) 55 | rootCmd.AddCommand(initCmd) 56 | } 57 | 58 | func initConfig() { 59 | if cfgFile != "" { 60 | // Use config file from the flag. 61 | viper.SetConfigFile(cfgFile) 62 | } else { 63 | // Find home directory. 64 | home, err := homedir.Dir() 65 | if err != nil { 66 | er(err) 67 | } 68 | 69 | // Search config in home directory with name ".cobra" (without extension). 70 | viper.AddConfigPath(home) 71 | viper.SetConfigName(".cobra") 72 | } 73 | 74 | viper.AutomaticEnv() 75 | 76 | if err := viper.ReadInConfig(); err == nil { 77 | fmt.Println("Using config file:", viper.ConfigFileUsed()) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/testdata/main.go.golden: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "github.com/spf13/testproject/cmd" 18 | 19 | func main() { 20 | cmd.Execute() 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/testdata/root.go.golden: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | "os" 20 | 21 | homedir "github.com/mitchellh/go-homedir" 22 | "github.com/spf13/cobra" 23 | "github.com/spf13/viper" 24 | ) 25 | 26 | var cfgFile string 27 | 28 | // RootCmd represents the base command when called without any subcommands 29 | var RootCmd = &cobra.Command{ 30 | Use: "testproject", 31 | Short: "A brief description of your application", 32 | Long: `A longer description that spans multiple lines and likely contains 33 | examples and usage of using your application. For example: 34 | 35 | Cobra is a CLI library for Go that empowers applications. 36 | This application is a tool to generate the needed files 37 | to quickly create a Cobra application.`, 38 | // Uncomment the following line if your bare application 39 | // has an action associated with it: 40 | // Run: func(cmd *cobra.Command, args []string) { }, 41 | } 42 | 43 | // Execute adds all child commands to the root command and sets flags appropriately. 44 | // This is called by main.main(). It only needs to happen once to the rootCmd. 45 | func Execute() { 46 | if err := RootCmd.Execute(); err != nil { 47 | fmt.Println(err) 48 | os.Exit(1) 49 | } 50 | } 51 | 52 | func init() { 53 | cobra.OnInitialize(initConfig) 54 | 55 | // Here you will define your flags and configuration settings. 56 | // Cobra supports persistent flags, which, if defined here, 57 | // will be global for your application. 58 | RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.testproject.yaml)") 59 | 60 | // Cobra also supports local flags, which will only run 61 | // when this action is called directly. 62 | RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 63 | } 64 | 65 | // initConfig reads in config file and ENV variables if set. 66 | func initConfig() { 67 | if cfgFile != "" { 68 | // Use config file from the flag. 69 | viper.SetConfigFile(cfgFile) 70 | } else { 71 | // Find home directory. 72 | home, err := homedir.Dir() 73 | if err != nil { 74 | fmt.Println(err) 75 | os.Exit(1) 76 | } 77 | 78 | // Search config in home directory with name ".testproject" (without extension). 79 | viper.AddConfigPath(home) 80 | viper.SetConfigName(".testproject") 81 | } 82 | 83 | viper.AutomaticEnv() // read in environment variables that match 84 | 85 | // If a config file is found, read it in. 86 | if err := viper.ReadInConfig(); err == nil { 87 | fmt.Println("Using config file:", viper.ConfigFileUsed()) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/cmd/testdata/test.go.golden: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | // testCmd represents the test command 24 | var testCmd = &cobra.Command{ 25 | Use: "test", 26 | Short: "A brief description of your command", 27 | Long: `A longer description that spans multiple lines and likely contains examples 28 | and usage of using your command. For example: 29 | 30 | Cobra is a CLI library for Go that empowers applications. 31 | This application is a tool to generate the needed files 32 | to quickly create a Cobra application.`, 33 | Run: func(cmd *cobra.Command, args []string) { 34 | fmt.Println("test called") 35 | }, 36 | } 37 | 38 | func init() { 39 | RootCmd.AddCommand(testCmd) 40 | 41 | // Here you will define your flags and configuration settings. 42 | 43 | // Cobra supports Persistent Flags which will work for this command 44 | // and all subcommands, e.g.: 45 | // testCmd.PersistentFlags().String("foo", "", "A help for foo") 46 | 47 | // Cobra supports local flags which will only run when this command 48 | // is called directly, e.g.: 49 | // testCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/cobra/main.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Steve Francia . 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import "github.com/spf13/cobra/cobra/cmd" 17 | 18 | func main() { 19 | cmd.Execute() 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_notwin.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package cobra 4 | 5 | var preExecHookFn func(*Command) 6 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_win.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package cobra 4 | 5 | import ( 6 | "os" 7 | "time" 8 | 9 | "github.com/inconshreveable/mousetrap" 10 | ) 11 | 12 | var preExecHookFn = preExecHook 13 | 14 | func preExecHook(c *Command) { 15 | if MousetrapHelpText != "" && mousetrap.StartedByExplorer() { 16 | c.Print(MousetrapHelpText) 17 | time.Sleep(5 * time.Second) 18 | os.Exit(1) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/doc/man_docs.md: -------------------------------------------------------------------------------- 1 | # Generating Man Pages For Your Own cobra.Command 2 | 3 | Generating man pages from a cobra command is incredibly easy. An example is as follows: 4 | 5 | ```go 6 | package main 7 | 8 | import ( 9 | "log" 10 | 11 | "github.com/spf13/cobra" 12 | "github.com/spf13/cobra/doc" 13 | ) 14 | 15 | func main() { 16 | cmd := &cobra.Command{ 17 | Use: "test", 18 | Short: "my test program", 19 | } 20 | header := &doc.GenManHeader{ 21 | Title: "MINE", 22 | Section: "3", 23 | } 24 | err := doc.GenManTree(cmd, header, "/tmp") 25 | if err != nil { 26 | log.Fatal(err) 27 | } 28 | } 29 | ``` 30 | 31 | That will get you a man page `/tmp/test.3` 32 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/doc/man_examples_test.go: -------------------------------------------------------------------------------- 1 | package doc_test 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | 7 | "github.com/spf13/cobra" 8 | "github.com/spf13/cobra/doc" 9 | ) 10 | 11 | func ExampleGenManTree() { 12 | cmd := &cobra.Command{ 13 | Use: "test", 14 | Short: "my test program", 15 | } 16 | header := &doc.GenManHeader{ 17 | Title: "MINE", 18 | Section: "3", 19 | } 20 | doc.GenManTree(cmd, header, "/tmp") 21 | } 22 | 23 | func ExampleGenMan() { 24 | cmd := &cobra.Command{ 25 | Use: "test", 26 | Short: "my test program", 27 | } 28 | header := &doc.GenManHeader{ 29 | Title: "MINE", 30 | Section: "3", 31 | } 32 | out := new(bytes.Buffer) 33 | doc.GenMan(cmd, header, out) 34 | fmt.Print(out.String()) 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/doc/md_docs.md: -------------------------------------------------------------------------------- 1 | # Generating Markdown Docs For Your Own cobra.Command 2 | 3 | Generating man pages from a cobra command is incredibly easy. An example is as follows: 4 | 5 | ```go 6 | package main 7 | 8 | import ( 9 | "log" 10 | 11 | "github.com/spf13/cobra" 12 | "github.com/spf13/cobra/doc" 13 | ) 14 | 15 | func main() { 16 | cmd := &cobra.Command{ 17 | Use: "test", 18 | Short: "my test program", 19 | } 20 | err := doc.GenMarkdownTree(cmd, "/tmp") 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | } 25 | ``` 26 | 27 | That will get you a Markdown document `/tmp/test.md` 28 | 29 | ## Generate markdown docs for the entire command tree 30 | 31 | This program can actually generate docs for the kubectl command in the kubernetes project 32 | 33 | ```go 34 | package main 35 | 36 | import ( 37 | "log" 38 | "io/ioutil" 39 | "os" 40 | 41 | "k8s.io/kubernetes/pkg/kubectl/cmd" 42 | cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" 43 | 44 | "github.com/spf13/cobra/doc" 45 | ) 46 | 47 | func main() { 48 | kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard) 49 | err := doc.GenMarkdownTree(kubectl, "./") 50 | if err != nil { 51 | log.Fatal(err) 52 | } 53 | } 54 | ``` 55 | 56 | This will generate a whole series of files, one for each command in the tree, in the directory specified (in this case "./") 57 | 58 | ## Generate markdown docs for a single command 59 | 60 | You may wish to have more control over the output, or only generate for a single command, instead of the entire command tree. If this is the case you may prefer to `GenMarkdown` instead of `GenMarkdownTree` 61 | 62 | ```go 63 | out := new(bytes.Buffer) 64 | err := doc.GenMarkdown(cmd, out) 65 | if err != nil { 66 | log.Fatal(err) 67 | } 68 | ``` 69 | 70 | This will write the markdown doc for ONLY "cmd" into the out, buffer. 71 | 72 | ## Customize the output 73 | 74 | Both `GenMarkdown` and `GenMarkdownTree` have alternate versions with callbacks to get some control of the output: 75 | 76 | ```go 77 | func GenMarkdownTreeCustom(cmd *Command, dir string, filePrepender, linkHandler func(string) string) error { 78 | //... 79 | } 80 | ``` 81 | 82 | ```go 83 | func GenMarkdownCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string) string) error { 84 | //... 85 | } 86 | ``` 87 | 88 | The `filePrepender` will prepend the return value given the full filepath to the rendered Markdown file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/): 89 | 90 | ```go 91 | const fmTemplate = `--- 92 | date: %s 93 | title: "%s" 94 | slug: %s 95 | url: %s 96 | --- 97 | ` 98 | 99 | filePrepender := func(filename string) string { 100 | now := time.Now().Format(time.RFC3339) 101 | name := filepath.Base(filename) 102 | base := strings.TrimSuffix(name, path.Ext(name)) 103 | url := "/commands/" + strings.ToLower(base) + "/" 104 | return fmt.Sprintf(fmTemplate, now, strings.Replace(base, "_", " ", -1), base, url) 105 | } 106 | ``` 107 | 108 | The `linkHandler` can be used to customize the rendered internal links to the commands, given a filename: 109 | 110 | ```go 111 | linkHandler := func(name string) string { 112 | base := strings.TrimSuffix(name, path.Ext(name)) 113 | return "/commands/" + strings.ToLower(base) + "/" 114 | } 115 | ``` 116 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/doc/rest_docs.md: -------------------------------------------------------------------------------- 1 | # Generating ReStructured Text Docs For Your Own cobra.Command 2 | 3 | Generating ReST pages from a cobra command is incredibly easy. An example is as follows: 4 | 5 | ```go 6 | package main 7 | 8 | import ( 9 | "log" 10 | 11 | "github.com/spf13/cobra" 12 | "github.com/spf13/cobra/doc" 13 | ) 14 | 15 | func main() { 16 | cmd := &cobra.Command{ 17 | Use: "test", 18 | Short: "my test program", 19 | } 20 | err := doc.GenReSTTree(cmd, "/tmp") 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | } 25 | ``` 26 | 27 | That will get you a ReST document `/tmp/test.rst` 28 | 29 | ## Generate ReST docs for the entire command tree 30 | 31 | This program can actually generate docs for the kubectl command in the kubernetes project 32 | 33 | ```go 34 | package main 35 | 36 | import ( 37 | "log" 38 | "io/ioutil" 39 | "os" 40 | 41 | "k8s.io/kubernetes/pkg/kubectl/cmd" 42 | cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" 43 | 44 | "github.com/spf13/cobra/doc" 45 | ) 46 | 47 | func main() { 48 | kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard) 49 | err := doc.GenReSTTree(kubectl, "./") 50 | if err != nil { 51 | log.Fatal(err) 52 | } 53 | } 54 | ``` 55 | 56 | This will generate a whole series of files, one for each command in the tree, in the directory specified (in this case "./") 57 | 58 | ## Generate ReST docs for a single command 59 | 60 | You may wish to have more control over the output, or only generate for a single command, instead of the entire command tree. If this is the case you may prefer to `GenReST` instead of `GenReSTTree` 61 | 62 | ```go 63 | out := new(bytes.Buffer) 64 | err := doc.GenReST(cmd, out) 65 | if err != nil { 66 | log.Fatal(err) 67 | } 68 | ``` 69 | 70 | This will write the ReST doc for ONLY "cmd" into the out, buffer. 71 | 72 | ## Customize the output 73 | 74 | Both `GenReST` and `GenReSTTree` have alternate versions with callbacks to get some control of the output: 75 | 76 | ```go 77 | func GenReSTTreeCustom(cmd *Command, dir string, filePrepender func(string) string, linkHandler func(string, string) string) error { 78 | //... 79 | } 80 | ``` 81 | 82 | ```go 83 | func GenReSTCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string, string) string) error { 84 | //... 85 | } 86 | ``` 87 | 88 | The `filePrepender` will prepend the return value given the full filepath to the rendered ReST file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/): 89 | 90 | ```go 91 | const fmTemplate = `--- 92 | date: %s 93 | title: "%s" 94 | slug: %s 95 | url: %s 96 | --- 97 | ` 98 | filePrepender := func(filename string) string { 99 | now := time.Now().Format(time.RFC3339) 100 | name := filepath.Base(filename) 101 | base := strings.TrimSuffix(name, path.Ext(name)) 102 | url := "/commands/" + strings.ToLower(base) + "/" 103 | return fmt.Sprintf(fmTemplate, now, strings.Replace(base, "_", " ", -1), base, url) 104 | } 105 | ``` 106 | 107 | The `linkHandler` can be used to customize the rendered links to the commands, given a command name and reference. This is useful while converting rst to html or while generating documentation with tools like Sphinx where `:ref:` is used: 108 | 109 | ```go 110 | // Sphinx cross-referencing format 111 | linkHandler := func(name, ref string) string { 112 | return fmt.Sprintf(":ref:`%s <%s>`", name, ref) 113 | } 114 | ``` 115 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/doc/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Red Hat Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package doc 15 | 16 | import ( 17 | "strings" 18 | 19 | "github.com/spf13/cobra" 20 | ) 21 | 22 | // Test to see if we have a reason to print See Also information in docs 23 | // Basically this is a test for a parent commend or a subcommand which is 24 | // both not deprecated and not the autogenerated help command. 25 | func hasSeeAlso(cmd *cobra.Command) bool { 26 | if cmd.HasParent() { 27 | return true 28 | } 29 | for _, c := range cmd.Commands() { 30 | if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { 31 | continue 32 | } 33 | return true 34 | } 35 | return false 36 | } 37 | 38 | // Temporary workaround for yaml lib generating incorrect yaml with long strings 39 | // that do not contain \n. 40 | func forceMultiLine(s string) string { 41 | if len(s) > 60 && !strings.Contains(s, "\n") { 42 | s = s + "\n" 43 | } 44 | return s 45 | } 46 | 47 | type byName []*cobra.Command 48 | 49 | func (s byName) Len() int { return len(s) } 50 | func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } 51 | func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() } 52 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/doc/yaml_docs.md: -------------------------------------------------------------------------------- 1 | # Generating Yaml Docs For Your Own cobra.Command 2 | 3 | Generating yaml files from a cobra command is incredibly easy. An example is as follows: 4 | 5 | ```go 6 | package main 7 | 8 | import ( 9 | "log" 10 | 11 | "github.com/spf13/cobra" 12 | "github.com/spf13/cobra/doc" 13 | ) 14 | 15 | func main() { 16 | cmd := &cobra.Command{ 17 | Use: "test", 18 | Short: "my test program", 19 | } 20 | err := doc.GenYamlTree(cmd, "/tmp") 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | } 25 | ``` 26 | 27 | That will get you a Yaml document `/tmp/test.yaml` 28 | 29 | ## Generate yaml docs for the entire command tree 30 | 31 | This program can actually generate docs for the kubectl command in the kubernetes project 32 | 33 | ```go 34 | package main 35 | 36 | import ( 37 | "io/ioutil" 38 | "log" 39 | "os" 40 | 41 | "k8s.io/kubernetes/pkg/kubectl/cmd" 42 | cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" 43 | 44 | "github.com/spf13/cobra/doc" 45 | ) 46 | 47 | func main() { 48 | kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard) 49 | err := doc.GenYamlTree(kubectl, "./") 50 | if err != nil { 51 | log.Fatal(err) 52 | } 53 | } 54 | ``` 55 | 56 | This will generate a whole series of files, one for each command in the tree, in the directory specified (in this case "./") 57 | 58 | ## Generate yaml docs for a single command 59 | 60 | You may wish to have more control over the output, or only generate for a single command, instead of the entire command tree. If this is the case you may prefer to `GenYaml` instead of `GenYamlTree` 61 | 62 | ```go 63 | out := new(bytes.Buffer) 64 | doc.GenYaml(cmd, out) 65 | ``` 66 | 67 | This will write the yaml doc for ONLY "cmd" into the out, buffer. 68 | 69 | ## Customize the output 70 | 71 | Both `GenYaml` and `GenYamlTree` have alternate versions with callbacks to get some control of the output: 72 | 73 | ```go 74 | func GenYamlTreeCustom(cmd *Command, dir string, filePrepender, linkHandler func(string) string) error { 75 | //... 76 | } 77 | ``` 78 | 79 | ```go 80 | func GenYamlCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string) string) error { 81 | //... 82 | } 83 | ``` 84 | 85 | The `filePrepender` will prepend the return value given the full filepath to the rendered Yaml file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/): 86 | 87 | ```go 88 | const fmTemplate = `--- 89 | date: %s 90 | title: "%s" 91 | slug: %s 92 | url: %s 93 | --- 94 | ` 95 | 96 | filePrepender := func(filename string) string { 97 | now := time.Now().Format(time.RFC3339) 98 | name := filepath.Base(filename) 99 | base := strings.TrimSuffix(name, path.Ext(name)) 100 | url := "/commands/" + strings.ToLower(base) + "/" 101 | return fmt.Sprintf(fmTemplate, now, strings.Replace(base, "_", " ", -1), base, url) 102 | } 103 | ``` 104 | 105 | The `linkHandler` can be used to customize the rendered internal links to the commands, given a filename: 106 | 107 | ```go 108 | linkHandler := func(name string) string { 109 | base := strings.TrimSuffix(name, path.Ext(name)) 110 | return "/commands/" + strings.ToLower(base) + "/" 111 | } 112 | ``` 113 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/zsh_completions.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | // GenZshCompletionFile generates zsh completion file. 12 | func (c *Command) GenZshCompletionFile(filename string) error { 13 | outFile, err := os.Create(filename) 14 | if err != nil { 15 | return err 16 | } 17 | defer outFile.Close() 18 | 19 | return c.GenZshCompletion(outFile) 20 | } 21 | 22 | // GenZshCompletion generates a zsh completion file and writes to the passed writer. 23 | func (c *Command) GenZshCompletion(w io.Writer) error { 24 | buf := new(bytes.Buffer) 25 | 26 | writeHeader(buf, c) 27 | maxDepth := maxDepth(c) 28 | writeLevelMapping(buf, maxDepth) 29 | writeLevelCases(buf, maxDepth, c) 30 | 31 | _, err := buf.WriteTo(w) 32 | return err 33 | } 34 | 35 | func writeHeader(w io.Writer, cmd *Command) { 36 | fmt.Fprintf(w, "#compdef %s\n\n", cmd.Name()) 37 | } 38 | 39 | func maxDepth(c *Command) int { 40 | if len(c.Commands()) == 0 { 41 | return 0 42 | } 43 | maxDepthSub := 0 44 | for _, s := range c.Commands() { 45 | subDepth := maxDepth(s) 46 | if subDepth > maxDepthSub { 47 | maxDepthSub = subDepth 48 | } 49 | } 50 | return 1 + maxDepthSub 51 | } 52 | 53 | func writeLevelMapping(w io.Writer, numLevels int) { 54 | fmt.Fprintln(w, `_arguments \`) 55 | for i := 1; i <= numLevels; i++ { 56 | fmt.Fprintf(w, ` '%d: :->level%d' \`, i, i) 57 | fmt.Fprintln(w) 58 | } 59 | fmt.Fprintf(w, ` '%d: :%s'`, numLevels+1, "_files") 60 | fmt.Fprintln(w) 61 | } 62 | 63 | func writeLevelCases(w io.Writer, maxDepth int, root *Command) { 64 | fmt.Fprintln(w, "case $state in") 65 | defer fmt.Fprintln(w, "esac") 66 | 67 | for i := 1; i <= maxDepth; i++ { 68 | fmt.Fprintf(w, " level%d)\n", i) 69 | writeLevel(w, root, i) 70 | fmt.Fprintln(w, " ;;") 71 | } 72 | fmt.Fprintln(w, " *)") 73 | fmt.Fprintln(w, " _arguments '*: :_files'") 74 | fmt.Fprintln(w, " ;;") 75 | } 76 | 77 | func writeLevel(w io.Writer, root *Command, i int) { 78 | fmt.Fprintf(w, " case $words[%d] in\n", i) 79 | defer fmt.Fprintln(w, " esac") 80 | 81 | commands := filterByLevel(root, i) 82 | byParent := groupByParent(commands) 83 | 84 | for p, c := range byParent { 85 | names := names(c) 86 | fmt.Fprintf(w, " %s)\n", p) 87 | fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " ")) 88 | fmt.Fprintln(w, " ;;") 89 | } 90 | fmt.Fprintln(w, " *)") 91 | fmt.Fprintln(w, " _arguments '*: :_files'") 92 | fmt.Fprintln(w, " ;;") 93 | 94 | } 95 | 96 | func filterByLevel(c *Command, l int) []*Command { 97 | cs := make([]*Command, 0) 98 | if l == 0 { 99 | cs = append(cs, c) 100 | return cs 101 | } 102 | for _, s := range c.Commands() { 103 | cs = append(cs, filterByLevel(s, l-1)...) 104 | } 105 | return cs 106 | } 107 | 108 | func groupByParent(commands []*Command) map[string][]*Command { 109 | m := make(map[string][]*Command) 110 | for _, c := range commands { 111 | parent := c.Parent() 112 | if parent == nil { 113 | continue 114 | } 115 | m[parent.Name()] = append(m[parent.Name()], c) 116 | } 117 | return m 118 | } 119 | 120 | func names(commands []*Command) []string { 121 | ns := make([]string, len(commands)) 122 | for i, c := range commands { 123 | ns[i] = c.Name() 124 | } 125 | return ns 126 | } 127 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/zsh_completions_test.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "bytes" 5 | "strings" 6 | "testing" 7 | ) 8 | 9 | func TestZshCompletion(t *testing.T) { 10 | tcs := []struct { 11 | name string 12 | root *Command 13 | expectedExpressions []string 14 | }{ 15 | { 16 | name: "trivial", 17 | root: &Command{Use: "trivialapp"}, 18 | expectedExpressions: []string{"#compdef trivial"}, 19 | }, 20 | { 21 | name: "linear", 22 | root: func() *Command { 23 | r := &Command{Use: "linear"} 24 | 25 | sub1 := &Command{Use: "sub1"} 26 | r.AddCommand(sub1) 27 | 28 | sub2 := &Command{Use: "sub2"} 29 | sub1.AddCommand(sub2) 30 | 31 | sub3 := &Command{Use: "sub3"} 32 | sub2.AddCommand(sub3) 33 | return r 34 | }(), 35 | expectedExpressions: []string{"sub1", "sub2", "sub3"}, 36 | }, 37 | { 38 | name: "flat", 39 | root: func() *Command { 40 | r := &Command{Use: "flat"} 41 | r.AddCommand(&Command{Use: "c1"}) 42 | r.AddCommand(&Command{Use: "c2"}) 43 | return r 44 | }(), 45 | expectedExpressions: []string{"(c1 c2)"}, 46 | }, 47 | { 48 | name: "tree", 49 | root: func() *Command { 50 | r := &Command{Use: "tree"} 51 | 52 | sub1 := &Command{Use: "sub1"} 53 | r.AddCommand(sub1) 54 | 55 | sub11 := &Command{Use: "sub11"} 56 | sub12 := &Command{Use: "sub12"} 57 | 58 | sub1.AddCommand(sub11) 59 | sub1.AddCommand(sub12) 60 | 61 | sub2 := &Command{Use: "sub2"} 62 | r.AddCommand(sub2) 63 | 64 | sub21 := &Command{Use: "sub21"} 65 | sub22 := &Command{Use: "sub22"} 66 | 67 | sub2.AddCommand(sub21) 68 | sub2.AddCommand(sub22) 69 | 70 | return r 71 | }(), 72 | expectedExpressions: []string{"(sub11 sub12)", "(sub21 sub22)"}, 73 | }, 74 | } 75 | 76 | for _, tc := range tcs { 77 | t.Run(tc.name, func(t *testing.T) { 78 | buf := new(bytes.Buffer) 79 | tc.root.GenZshCompletion(buf) 80 | completion := buf.String() 81 | for _, expectedExpression := range tc.expectedExpressions { 82 | if !strings.Contains(completion, expectedExpression) { 83 | t.Errorf("expected completion to contain '%v' somewhere; got '%v'", expectedExpression, completion) 84 | } 85 | } 86 | }) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | 3 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.7.3 7 | - 1.8.1 8 | - tip 9 | 10 | matrix: 11 | allow_failures: 12 | - go: tip 13 | 14 | install: 15 | - go get github.com/golang/lint/golint 16 | - export PATH=$GOPATH/bin:$PATH 17 | - go install ./... 18 | 19 | script: 20 | - verify/all.sh -v 21 | - go test ./... 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/bool.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // optional interface to indicate boolean flags that can be 6 | // supplied without "=value" text 7 | type boolFlag interface { 8 | Value 9 | IsBoolFlag() bool 10 | } 11 | 12 | // -- bool Value 13 | type boolValue bool 14 | 15 | func newBoolValue(val bool, p *bool) *boolValue { 16 | *p = val 17 | return (*boolValue)(p) 18 | } 19 | 20 | func (b *boolValue) Set(s string) error { 21 | v, err := strconv.ParseBool(s) 22 | *b = boolValue(v) 23 | return err 24 | } 25 | 26 | func (b *boolValue) Type() string { 27 | return "bool" 28 | } 29 | 30 | func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) } 31 | 32 | func (b *boolValue) IsBoolFlag() bool { return true } 33 | 34 | func boolConv(sval string) (interface{}, error) { 35 | return strconv.ParseBool(sval) 36 | } 37 | 38 | // GetBool return the bool value of a flag with the given name 39 | func (f *FlagSet) GetBool(name string) (bool, error) { 40 | val, err := f.getFlagType(name, "bool", boolConv) 41 | if err != nil { 42 | return false, err 43 | } 44 | return val.(bool), nil 45 | } 46 | 47 | // BoolVar defines a bool flag with specified name, default value, and usage string. 48 | // The argument p points to a bool variable in which to store the value of the flag. 49 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { 50 | f.BoolVarP(p, name, "", value, usage) 51 | } 52 | 53 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 54 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 55 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) 56 | flag.NoOptDefVal = "true" 57 | } 58 | 59 | // BoolVar defines a bool flag with specified name, default value, and usage string. 60 | // The argument p points to a bool variable in which to store the value of the flag. 61 | func BoolVar(p *bool, name string, value bool, usage string) { 62 | BoolVarP(p, name, "", value, usage) 63 | } 64 | 65 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 66 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 67 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) 68 | flag.NoOptDefVal = "true" 69 | } 70 | 71 | // Bool defines a bool flag with specified name, default value, and usage string. 72 | // The return value is the address of a bool variable that stores the value of the flag. 73 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool { 74 | return f.BoolP(name, "", value, usage) 75 | } 76 | 77 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 78 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { 79 | p := new(bool) 80 | f.BoolVarP(p, name, shorthand, value, usage) 81 | return p 82 | } 83 | 84 | // Bool defines a bool flag with specified name, default value, and usage string. 85 | // The return value is the address of a bool variable that stores the value of the flag. 86 | func Bool(name string, value bool, usage string) *bool { 87 | return BoolP(name, "", value, usage) 88 | } 89 | 90 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 91 | func BoolP(name, shorthand string, value bool, usage string) *bool { 92 | b := CommandLine.BoolP(name, shorthand, value, usage) 93 | return b 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- count Value 6 | type countValue int 7 | 8 | func newCountValue(val int, p *int) *countValue { 9 | *p = val 10 | return (*countValue)(p) 11 | } 12 | 13 | func (i *countValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | // -1 means that no specific value was passed, so increment 16 | if v == -1 { 17 | *i = countValue(*i + 1) 18 | } else { 19 | *i = countValue(v) 20 | } 21 | return err 22 | } 23 | 24 | func (i *countValue) Type() string { 25 | return "count" 26 | } 27 | 28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) } 29 | 30 | func countConv(sval string) (interface{}, error) { 31 | i, err := strconv.Atoi(sval) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return i, nil 36 | } 37 | 38 | // GetCount return the int value of a flag with the given name 39 | func (f *FlagSet) GetCount(name string) (int, error) { 40 | val, err := f.getFlagType(name, "count", countConv) 41 | if err != nil { 42 | return 0, err 43 | } 44 | return val.(int), nil 45 | } 46 | 47 | // CountVar defines a count flag with specified name, default value, and usage string. 48 | // The argument p points to an int variable in which to store the value of the flag. 49 | // A count flag will add 1 to its value evey time it is found on the command line 50 | func (f *FlagSet) CountVar(p *int, name string, usage string) { 51 | f.CountVarP(p, name, "", usage) 52 | } 53 | 54 | // CountVarP is like CountVar only take a shorthand for the flag name. 55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { 56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) 57 | flag.NoOptDefVal = "-1" 58 | } 59 | 60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set 61 | func CountVar(p *int, name string, usage string) { 62 | CommandLine.CountVar(p, name, usage) 63 | } 64 | 65 | // CountVarP is like CountVar only take a shorthand for the flag name. 66 | func CountVarP(p *int, name, shorthand string, usage string) { 67 | CommandLine.CountVarP(p, name, shorthand, usage) 68 | } 69 | 70 | // Count defines a count flag with specified name, default value, and usage string. 71 | // The return value is the address of an int variable that stores the value of the flag. 72 | // A count flag will add 1 to its value evey time it is found on the command line 73 | func (f *FlagSet) Count(name string, usage string) *int { 74 | p := new(int) 75 | f.CountVarP(p, name, "", usage) 76 | return p 77 | } 78 | 79 | // CountP is like Count only takes a shorthand for the flag name. 80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int { 81 | p := new(int) 82 | f.CountVarP(p, name, shorthand, usage) 83 | return p 84 | } 85 | 86 | // Count defines a count flag with specified name, default value, and usage string. 87 | // The return value is the address of an int variable that stores the value of the flag. 88 | // A count flag will add 1 to its value evey time it is found on the command line 89 | func Count(name string, usage string) *int { 90 | return CommandLine.CountP(name, "", usage) 91 | } 92 | 93 | // CountP is like Count only takes a shorthand for the flag name. 94 | func CountP(name, shorthand string, usage string) *int { 95 | return CommandLine.CountP(name, shorthand, usage) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count_test.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | func setUpCount(c *int) *FlagSet { 9 | f := NewFlagSet("test", ContinueOnError) 10 | f.CountVarP(c, "verbose", "v", "a counter") 11 | return f 12 | } 13 | 14 | func TestCount(t *testing.T) { 15 | testCases := []struct { 16 | input []string 17 | success bool 18 | expected int 19 | }{ 20 | {[]string{"-vvv"}, true, 3}, 21 | {[]string{"-v", "-v", "-v"}, true, 3}, 22 | {[]string{"-v", "--verbose", "-v"}, true, 3}, 23 | {[]string{"-v=3", "-v"}, true, 4}, 24 | {[]string{"-v=a"}, false, 0}, 25 | } 26 | 27 | devnull, _ := os.Open(os.DevNull) 28 | os.Stderr = devnull 29 | for i := range testCases { 30 | var count int 31 | f := setUpCount(&count) 32 | 33 | tc := &testCases[i] 34 | 35 | err := f.Parse(tc.input) 36 | if err != nil && tc.success == true { 37 | t.Errorf("expected success, got %q", err) 38 | continue 39 | } else if err == nil && tc.success == false { 40 | t.Errorf("expected failure, got success") 41 | continue 42 | } else if tc.success { 43 | c, err := f.GetCount("verbose") 44 | if err != nil { 45 | t.Errorf("Got error trying to fetch the counter flag") 46 | } 47 | if c != tc.expected { 48 | t.Errorf("expected %q, got %q", tc.expected, c) 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/duration.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // -- time.Duration Value 8 | type durationValue time.Duration 9 | 10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue { 11 | *p = val 12 | return (*durationValue)(p) 13 | } 14 | 15 | func (d *durationValue) Set(s string) error { 16 | v, err := time.ParseDuration(s) 17 | *d = durationValue(v) 18 | return err 19 | } 20 | 21 | func (d *durationValue) Type() string { 22 | return "duration" 23 | } 24 | 25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() } 26 | 27 | func durationConv(sval string) (interface{}, error) { 28 | return time.ParseDuration(sval) 29 | } 30 | 31 | // GetDuration return the duration value of a flag with the given name 32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) { 33 | val, err := f.getFlagType(name, "duration", durationConv) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return val.(time.Duration), nil 38 | } 39 | 40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 41 | // The argument p points to a time.Duration variable in which to store the value of the flag. 42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 43 | f.VarP(newDurationValue(value, p), name, "", usage) 44 | } 45 | 46 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 48 | f.VarP(newDurationValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 52 | // The argument p points to a time.Duration variable in which to store the value of the flag. 53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage) 55 | } 56 | 57 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 63 | // The return value is the address of a time.Duration variable that stores the value of the flag. 64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { 65 | p := new(time.Duration) 66 | f.DurationVarP(p, name, "", value, usage) 67 | return p 68 | } 69 | 70 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 72 | p := new(time.Duration) 73 | f.DurationVarP(p, name, shorthand, value, usage) 74 | return p 75 | } 76 | 77 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 78 | // The return value is the address of a time.Duration variable that stores the value of the flag. 79 | func Duration(name string, value time.Duration, usage string) *time.Duration { 80 | return CommandLine.DurationP(name, "", value, usage) 81 | } 82 | 83 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 85 | return CommandLine.DurationP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag_test 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/spf13/pflag" 11 | ) 12 | 13 | func ExampleShorthandLookup() { 14 | name := "verbose" 15 | short := name[:1] 16 | 17 | pflag.BoolP(name, short, false, "verbose output") 18 | 19 | // len(short) must be == 1 20 | flag := pflag.ShorthandLookup(short) 21 | 22 | fmt.Println(flag.Name) 23 | } 24 | 25 | func ExampleFlagSet_ShorthandLookup() { 26 | name := "verbose" 27 | short := name[:1] 28 | 29 | fs := pflag.NewFlagSet("Example", pflag.ContinueOnError) 30 | fs.BoolP(name, short, false, "verbose output") 31 | 32 | // len(short) must be == 1 33 | flag := fs.ShorthandLookup(short) 34 | 35 | fmt.Println(flag.Name) 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | "io/ioutil" 9 | "os" 10 | ) 11 | 12 | // Additional routines compiled into the package only during testing. 13 | 14 | // ResetForTesting clears all flag state and sets the usage function as directed. 15 | // After calling ResetForTesting, parse errors in flag handling will not 16 | // exit the program. 17 | func ResetForTesting(usage func()) { 18 | CommandLine = &FlagSet{ 19 | name: os.Args[0], 20 | errorHandling: ContinueOnError, 21 | output: ioutil.Discard, 22 | } 23 | Usage = usage 24 | } 25 | 26 | // GetCommandLine returns the default FlagSet. 27 | func GetCommandLine() *FlagSet { 28 | return CommandLine 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float32 Value 6 | type float32Value float32 7 | 8 | func newFloat32Value(val float32, p *float32) *float32Value { 9 | *p = val 10 | return (*float32Value)(p) 11 | } 12 | 13 | func (f *float32Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 32) 15 | *f = float32Value(v) 16 | return err 17 | } 18 | 19 | func (f *float32Value) Type() string { 20 | return "float32" 21 | } 22 | 23 | func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } 24 | 25 | func float32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseFloat(sval, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return float32(v), nil 31 | } 32 | 33 | // GetFloat32 return the float32 value of a flag with the given name 34 | func (f *FlagSet) GetFloat32(name string) (float32, error) { 35 | val, err := f.getFlagType(name, "float32", float32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(float32), nil 40 | } 41 | 42 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 43 | // The argument p points to a float32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { 45 | f.VarP(newFloat32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 50 | f.VarP(newFloat32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 54 | // The argument p points to a float32 variable in which to store the value of the flag. 55 | func Float32Var(p *float32, name string, value float32, usage string) { 56 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 61 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Float32 defines a float32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a float32 variable that stores the value of the flag. 66 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { 67 | p := new(float32) 68 | f.Float32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { 74 | p := new(float32) 75 | f.Float32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Float32 defines a float32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a float32 variable that stores the value of the flag. 81 | func Float32(name string, value float32, usage string) *float32 { 82 | return CommandLine.Float32P(name, "", value, usage) 83 | } 84 | 85 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 86 | func Float32P(name, shorthand string, value float32, usage string) *float32 { 87 | return CommandLine.Float32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float64 Value 6 | type float64Value float64 7 | 8 | func newFloat64Value(val float64, p *float64) *float64Value { 9 | *p = val 10 | return (*float64Value)(p) 11 | } 12 | 13 | func (f *float64Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 64) 15 | *f = float64Value(v) 16 | return err 17 | } 18 | 19 | func (f *float64Value) Type() string { 20 | return "float64" 21 | } 22 | 23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } 24 | 25 | func float64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseFloat(sval, 64) 27 | } 28 | 29 | // GetFloat64 return the float64 value of a flag with the given name 30 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 31 | val, err := f.getFlagType(name, "float64", float64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(float64), nil 36 | } 37 | 38 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 39 | // The argument p points to a float64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 41 | f.VarP(newFloat64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 50 | // The argument p points to a float64 variable in which to store the value of the flag. 51 | func Float64Var(p *float64, name string, value float64, usage string) { 52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Float64 defines a float64 flag with specified name, default value, and usage string. 61 | // The return value is the address of a float64 variable that stores the value of the flag. 62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 63 | p := new(float64) 64 | f.Float64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 70 | p := new(float64) 71 | f.Float64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Float64 defines a float64 flag with specified name, default value, and usage string. 76 | // The return value is the address of a float64 variable that stores the value of the flag. 77 | func Float64(name string, value float64, usage string) *float64 { 78 | return CommandLine.Float64P(name, "", value, usage) 79 | } 80 | 81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 82 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 83 | return CommandLine.Float64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "reflect" 10 | "strings" 11 | ) 12 | 13 | // flagValueWrapper implements pflag.Value around a flag.Value. The main 14 | // difference here is the addition of the Type method that returns a string 15 | // name of the type. As this is generally unknown, we approximate that with 16 | // reflection. 17 | type flagValueWrapper struct { 18 | inner goflag.Value 19 | flagType string 20 | } 21 | 22 | // We are just copying the boolFlag interface out of goflag as that is what 23 | // they use to decide if a flag should get "true" when no arg is given. 24 | type goBoolFlag interface { 25 | goflag.Value 26 | IsBoolFlag() bool 27 | } 28 | 29 | func wrapFlagValue(v goflag.Value) Value { 30 | // If the flag.Value happens to also be a pflag.Value, just use it directly. 31 | if pv, ok := v.(Value); ok { 32 | return pv 33 | } 34 | 35 | pv := &flagValueWrapper{ 36 | inner: v, 37 | } 38 | 39 | t := reflect.TypeOf(v) 40 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { 41 | t = t.Elem() 42 | } 43 | 44 | pv.flagType = strings.TrimSuffix(t.Name(), "Value") 45 | return pv 46 | } 47 | 48 | func (v *flagValueWrapper) String() string { 49 | return v.inner.String() 50 | } 51 | 52 | func (v *flagValueWrapper) Set(s string) error { 53 | return v.inner.Set(s) 54 | } 55 | 56 | func (v *flagValueWrapper) Type() string { 57 | return v.flagType 58 | } 59 | 60 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag 61 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei 62 | // with both `-v` and `--v` in flags. If the golang flag was more than a single 63 | // character (ex: `verbose`) it will only be accessible via `--verbose` 64 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { 65 | // Remember the default value as a string; it won't change. 66 | flag := &Flag{ 67 | Name: goflag.Name, 68 | Usage: goflag.Usage, 69 | Value: wrapFlagValue(goflag.Value), 70 | // Looks like golang flags don't set DefValue correctly :-( 71 | //DefValue: goflag.DefValue, 72 | DefValue: goflag.Value.String(), 73 | } 74 | // Ex: if the golang flag was -v, allow both -v and --v to work 75 | if len(flag.Name) == 1 { 76 | flag.Shorthand = flag.Name 77 | } 78 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { 79 | flag.NoOptDefVal = "true" 80 | } 81 | return flag 82 | } 83 | 84 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet 85 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { 86 | if f.Lookup(goflag.Name) != nil { 87 | return 88 | } 89 | newflag := PFlagFromGoFlag(goflag) 90 | f.AddFlag(newflag) 91 | } 92 | 93 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet 94 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { 95 | if newSet == nil { 96 | return 97 | } 98 | newSet.VisitAll(func(goflag *goflag.Flag) { 99 | f.AddGoFlag(goflag) 100 | }) 101 | } 102 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "testing" 10 | ) 11 | 12 | func TestGoflags(t *testing.T) { 13 | goflag.String("stringFlag", "stringFlag", "stringFlag") 14 | goflag.Bool("boolFlag", false, "boolFlag") 15 | 16 | f := NewFlagSet("test", ContinueOnError) 17 | 18 | f.AddGoFlagSet(goflag.CommandLine) 19 | err := f.Parse([]string{"--stringFlag=bob", "--boolFlag"}) 20 | if err != nil { 21 | t.Fatal("expected no error; get", err) 22 | } 23 | 24 | getString, err := f.GetString("stringFlag") 25 | if err != nil { 26 | t.Fatal("expected no error; get", err) 27 | } 28 | if getString != "bob" { 29 | t.Fatalf("expected getString=bob but got getString=%s", getString) 30 | } 31 | 32 | getBool, err := f.GetBool("boolFlag") 33 | if err != nil { 34 | t.Fatal("expected no error; get", err) 35 | } 36 | if getBool != true { 37 | t.Fatalf("expected getBool=true but got getBool=%v", getBool) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int Value 6 | type intValue int 7 | 8 | func newIntValue(val int, p *int) *intValue { 9 | *p = val 10 | return (*intValue)(p) 11 | } 12 | 13 | func (i *intValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = intValue(v) 16 | return err 17 | } 18 | 19 | func (i *intValue) Type() string { 20 | return "int" 21 | } 22 | 23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) } 24 | 25 | func intConv(sval string) (interface{}, error) { 26 | return strconv.Atoi(sval) 27 | } 28 | 29 | // GetInt return the int value of a flag with the given name 30 | func (f *FlagSet) GetInt(name string) (int, error) { 31 | val, err := f.getFlagType(name, "int", intConv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int), nil 36 | } 37 | 38 | // IntVar defines an int flag with specified name, default value, and usage string. 39 | // The argument p points to an int variable in which to store the value of the flag. 40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 41 | f.VarP(newIntValue(value, p), name, "", usage) 42 | } 43 | 44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 46 | f.VarP(newIntValue(value, p), name, shorthand, usage) 47 | } 48 | 49 | // IntVar defines an int flag with specified name, default value, and usage string. 50 | // The argument p points to an int variable in which to store the value of the flag. 51 | func IntVar(p *int, name string, value int, usage string) { 52 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 53 | } 54 | 55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 56 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int defines an int flag with specified name, default value, and usage string. 61 | // The return value is the address of an int variable that stores the value of the flag. 62 | func (f *FlagSet) Int(name string, value int, usage string) *int { 63 | p := new(int) 64 | f.IntVarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 70 | p := new(int) 71 | f.IntVarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int defines an int flag with specified name, default value, and usage string. 76 | // The return value is the address of an int variable that stores the value of the flag. 77 | func Int(name string, value int, usage string) *int { 78 | return CommandLine.IntP(name, "", value, usage) 79 | } 80 | 81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 82 | func IntP(name, shorthand string, value int, usage string) *int { 83 | return CommandLine.IntP(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int32 Value 6 | type int32Value int32 7 | 8 | func newInt32Value(val int32, p *int32) *int32Value { 9 | *p = val 10 | return (*int32Value)(p) 11 | } 12 | 13 | func (i *int32Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 32) 15 | *i = int32Value(v) 16 | return err 17 | } 18 | 19 | func (i *int32Value) Type() string { 20 | return "int32" 21 | } 22 | 23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int32(v), nil 31 | } 32 | 33 | // GetInt32 return the int32 value of a flag with the given name 34 | func (f *FlagSet) GetInt32(name string) (int32, error) { 35 | val, err := f.getFlagType(name, "int32", int32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int32), nil 40 | } 41 | 42 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 43 | // The argument p points to an int32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 45 | f.VarP(newInt32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 50 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 54 | // The argument p points to an int32 variable in which to store the value of the flag. 55 | func Int32Var(p *int32, name string, value int32, usage string) { 56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int32 defines an int32 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int32 variable that stores the value of the flag. 66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 67 | p := new(int32) 68 | f.Int32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 74 | p := new(int32) 75 | f.Int32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int32 defines an int32 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int32 variable that stores the value of the flag. 81 | func Int32(name string, value int32, usage string) *int32 { 82 | return CommandLine.Int32P(name, "", value, usage) 83 | } 84 | 85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 86 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 87 | return CommandLine.Int32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int64 Value 6 | type int64Value int64 7 | 8 | func newInt64Value(val int64, p *int64) *int64Value { 9 | *p = val 10 | return (*int64Value)(p) 11 | } 12 | 13 | func (i *int64Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = int64Value(v) 16 | return err 17 | } 18 | 19 | func (i *int64Value) Type() string { 20 | return "int64" 21 | } 22 | 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseInt(sval, 0, 64) 27 | } 28 | 29 | // GetInt64 return the int64 value of a flag with the given name 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { 31 | val, err := f.getFlagType(name, "int64", int64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int64), nil 36 | } 37 | 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 39 | // The argument p points to an int64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 41 | f.VarP(newInt64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 50 | // The argument p points to an int64 variable in which to store the value of the flag. 51 | func Int64Var(p *int64, name string, value int64, usage string) { 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. 61 | // The return value is the address of an int64 variable that stores the value of the flag. 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 63 | p := new(int64) 64 | f.Int64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 70 | p := new(int64) 71 | f.Int64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. 76 | // The return value is the address of an int64 variable that stores the value of the flag. 77 | func Int64(name string, value int64, usage string) *int64 { 78 | return CommandLine.Int64P(name, "", value, usage) 79 | } 80 | 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 83 | return CommandLine.Int64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int8 Value 6 | type int8Value int8 7 | 8 | func newInt8Value(val int8, p *int8) *int8Value { 9 | *p = val 10 | return (*int8Value)(p) 11 | } 12 | 13 | func (i *int8Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 8) 15 | *i = int8Value(v) 16 | return err 17 | } 18 | 19 | func (i *int8Value) Type() string { 20 | return "int8" 21 | } 22 | 23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int8(v), nil 31 | } 32 | 33 | // GetInt8 return the int8 value of a flag with the given name 34 | func (f *FlagSet) GetInt8(name string) (int8, error) { 35 | val, err := f.getFlagType(name, "int8", int8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int8), nil 40 | } 41 | 42 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 43 | // The argument p points to an int8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 45 | f.VarP(newInt8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 50 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 54 | // The argument p points to an int8 variable in which to store the value of the flag. 55 | func Int8Var(p *int8, name string, value int8, usage string) { 56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int8 defines an int8 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int8 variable that stores the value of the flag. 66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 67 | p := new(int8) 68 | f.Int8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 74 | p := new(int8) 75 | f.Int8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int8 defines an int8 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int8 variable that stores the value of the flag. 81 | func Int8(name string, value int8, usage string) *int8 { 82 | return CommandLine.Int8P(name, "", value, usage) 83 | } 84 | 85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 86 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 87 | return CommandLine.Int8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // -- net.IP value 10 | type ipValue net.IP 11 | 12 | func newIPValue(val net.IP, p *net.IP) *ipValue { 13 | *p = val 14 | return (*ipValue)(p) 15 | } 16 | 17 | func (i *ipValue) String() string { return net.IP(*i).String() } 18 | func (i *ipValue) Set(s string) error { 19 | ip := net.ParseIP(strings.TrimSpace(s)) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP: %q", s) 22 | } 23 | *i = ipValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipValue) Type() string { 28 | return "ip" 29 | } 30 | 31 | func ipConv(sval string) (interface{}, error) { 32 | ip := net.ParseIP(sval) 33 | if ip != nil { 34 | return ip, nil 35 | } 36 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 37 | } 38 | 39 | // GetIP return the net.IP value of a flag with the given name 40 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 41 | val, err := f.getFlagType(name, "ip", ipConv) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return val.(net.IP), nil 46 | } 47 | 48 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 49 | // The argument p points to an net.IP variable in which to store the value of the flag. 50 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 51 | f.VarP(newIPValue(value, p), name, "", usage) 52 | } 53 | 54 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 55 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 56 | f.VarP(newIPValue(value, p), name, shorthand, usage) 57 | } 58 | 59 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 60 | // The argument p points to an net.IP variable in which to store the value of the flag. 61 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 62 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 63 | } 64 | 65 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 66 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 67 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 68 | } 69 | 70 | // IP defines an net.IP flag with specified name, default value, and usage string. 71 | // The return value is the address of an net.IP variable that stores the value of the flag. 72 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 73 | p := new(net.IP) 74 | f.IPVarP(p, name, "", value, usage) 75 | return p 76 | } 77 | 78 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 79 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 80 | p := new(net.IP) 81 | f.IPVarP(p, name, shorthand, value, usage) 82 | return p 83 | } 84 | 85 | // IP defines an net.IP flag with specified name, default value, and usage string. 86 | // The return value is the address of an net.IP variable that stores the value of the flag. 87 | func IP(name string, value net.IP, usage string) *net.IP { 88 | return CommandLine.IPP(name, "", value, usage) 89 | } 90 | 91 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 92 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 93 | return CommandLine.IPP(name, shorthand, value, usage) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip_test.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "os" 7 | "testing" 8 | ) 9 | 10 | func setUpIP(ip *net.IP) *FlagSet { 11 | f := NewFlagSet("test", ContinueOnError) 12 | f.IPVar(ip, "address", net.ParseIP("0.0.0.0"), "IP Address") 13 | return f 14 | } 15 | 16 | func TestIP(t *testing.T) { 17 | testCases := []struct { 18 | input string 19 | success bool 20 | expected string 21 | }{ 22 | {"0.0.0.0", true, "0.0.0.0"}, 23 | {" 0.0.0.0 ", true, "0.0.0.0"}, 24 | {"1.2.3.4", true, "1.2.3.4"}, 25 | {"127.0.0.1", true, "127.0.0.1"}, 26 | {"255.255.255.255", true, "255.255.255.255"}, 27 | {"", false, ""}, 28 | {"0", false, ""}, 29 | {"localhost", false, ""}, 30 | {"0.0.0", false, ""}, 31 | {"0.0.0.", false, ""}, 32 | {"0.0.0.0.", false, ""}, 33 | {"0.0.0.256", false, ""}, 34 | {"0 . 0 . 0 . 0", false, ""}, 35 | } 36 | 37 | devnull, _ := os.Open(os.DevNull) 38 | os.Stderr = devnull 39 | for i := range testCases { 40 | var addr net.IP 41 | f := setUpIP(&addr) 42 | 43 | tc := &testCases[i] 44 | 45 | arg := fmt.Sprintf("--address=%s", tc.input) 46 | err := f.Parse([]string{arg}) 47 | if err != nil && tc.success == true { 48 | t.Errorf("expected success, got %q", err) 49 | continue 50 | } else if err == nil && tc.success == false { 51 | t.Errorf("expected failure") 52 | continue 53 | } else if tc.success { 54 | ip, err := f.GetIP("address") 55 | if err != nil { 56 | t.Errorf("Got error trying to fetch the IP flag: %v", err) 57 | } 58 | if ip.String() != tc.expected { 59 | t.Errorf("expected %q, got %q", tc.expected, ip.String()) 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipnet.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // IPNet adapts net.IPNet for use as a flag. 10 | type ipNetValue net.IPNet 11 | 12 | func (ipnet ipNetValue) String() string { 13 | n := net.IPNet(ipnet) 14 | return n.String() 15 | } 16 | 17 | func (ipnet *ipNetValue) Set(value string) error { 18 | _, n, err := net.ParseCIDR(strings.TrimSpace(value)) 19 | if err != nil { 20 | return err 21 | } 22 | *ipnet = ipNetValue(*n) 23 | return nil 24 | } 25 | 26 | func (*ipNetValue) Type() string { 27 | return "ipNet" 28 | } 29 | 30 | func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { 31 | *p = val 32 | return (*ipNetValue)(p) 33 | } 34 | 35 | func ipNetConv(sval string) (interface{}, error) { 36 | _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) 37 | if err == nil { 38 | return *n, nil 39 | } 40 | return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval) 41 | } 42 | 43 | // GetIPNet return the net.IPNet value of a flag with the given name 44 | func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) { 45 | val, err := f.getFlagType(name, "ipNet", ipNetConv) 46 | if err != nil { 47 | return net.IPNet{}, err 48 | } 49 | return val.(net.IPNet), nil 50 | } 51 | 52 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 53 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 54 | func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 55 | f.VarP(newIPNetValue(value, p), name, "", usage) 56 | } 57 | 58 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 59 | func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 60 | f.VarP(newIPNetValue(value, p), name, shorthand, usage) 61 | } 62 | 63 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 64 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 65 | func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 66 | CommandLine.VarP(newIPNetValue(value, p), name, "", usage) 67 | } 68 | 69 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 70 | func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 71 | CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) 72 | } 73 | 74 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 75 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 76 | func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { 77 | p := new(net.IPNet) 78 | f.IPNetVarP(p, name, "", value, usage) 79 | return p 80 | } 81 | 82 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 84 | p := new(net.IPNet) 85 | f.IPNetVarP(p, name, shorthand, value, usage) 86 | return p 87 | } 88 | 89 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 90 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 91 | func IPNet(name string, value net.IPNet, usage string) *net.IPNet { 92 | return CommandLine.IPNetP(name, "", value, usage) 93 | } 94 | 95 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 96 | func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 97 | return CommandLine.IPNetP(name, shorthand, value, usage) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipnet_test.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "os" 7 | "testing" 8 | ) 9 | 10 | func setUpIPNet(ip *net.IPNet) *FlagSet { 11 | f := NewFlagSet("test", ContinueOnError) 12 | _, def, _ := net.ParseCIDR("0.0.0.0/0") 13 | f.IPNetVar(ip, "address", *def, "IP Address") 14 | return f 15 | } 16 | 17 | func TestIPNet(t *testing.T) { 18 | testCases := []struct { 19 | input string 20 | success bool 21 | expected string 22 | }{ 23 | {"0.0.0.0/0", true, "0.0.0.0/0"}, 24 | {" 0.0.0.0/0 ", true, "0.0.0.0/0"}, 25 | {"1.2.3.4/8", true, "1.0.0.0/8"}, 26 | {"127.0.0.1/16", true, "127.0.0.0/16"}, 27 | {"255.255.255.255/19", true, "255.255.224.0/19"}, 28 | {"255.255.255.255/32", true, "255.255.255.255/32"}, 29 | {"", false, ""}, 30 | {"/0", false, ""}, 31 | {"0", false, ""}, 32 | {"0/0", false, ""}, 33 | {"localhost/0", false, ""}, 34 | {"0.0.0/4", false, ""}, 35 | {"0.0.0./8", false, ""}, 36 | {"0.0.0.0./12", false, ""}, 37 | {"0.0.0.256/16", false, ""}, 38 | {"0.0.0.0 /20", false, ""}, 39 | {"0.0.0.0/ 24", false, ""}, 40 | {"0 . 0 . 0 . 0 / 28", false, ""}, 41 | {"0.0.0.0/33", false, ""}, 42 | } 43 | 44 | devnull, _ := os.Open(os.DevNull) 45 | os.Stderr = devnull 46 | for i := range testCases { 47 | var addr net.IPNet 48 | f := setUpIPNet(&addr) 49 | 50 | tc := &testCases[i] 51 | 52 | arg := fmt.Sprintf("--address=%s", tc.input) 53 | err := f.Parse([]string{arg}) 54 | if err != nil && tc.success == true { 55 | t.Errorf("expected success, got %q", err) 56 | continue 57 | } else if err == nil && tc.success == false { 58 | t.Errorf("expected failure") 59 | continue 60 | } else if tc.success { 61 | ip, err := f.GetIPNet("address") 62 | if err != nil { 63 | t.Errorf("Got error trying to fetch the IP flag: %v", err) 64 | } 65 | if ip.String() != tc.expected { 66 | t.Errorf("expected %q, got %q", tc.expected, ip.String()) 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- string Value 4 | type stringValue string 5 | 6 | func newStringValue(val string, p *string) *stringValue { 7 | *p = val 8 | return (*stringValue)(p) 9 | } 10 | 11 | func (s *stringValue) Set(val string) error { 12 | *s = stringValue(val) 13 | return nil 14 | } 15 | func (s *stringValue) Type() string { 16 | return "string" 17 | } 18 | 19 | func (s *stringValue) String() string { return string(*s) } 20 | 21 | func stringConv(sval string) (interface{}, error) { 22 | return sval, nil 23 | } 24 | 25 | // GetString return the string value of a flag with the given name 26 | func (f *FlagSet) GetString(name string) (string, error) { 27 | val, err := f.getFlagType(name, "string", stringConv) 28 | if err != nil { 29 | return "", err 30 | } 31 | return val.(string), nil 32 | } 33 | 34 | // StringVar defines a string flag with specified name, default value, and usage string. 35 | // The argument p points to a string variable in which to store the value of the flag. 36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 37 | f.VarP(newStringValue(value, p), name, "", usage) 38 | } 39 | 40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 42 | f.VarP(newStringValue(value, p), name, shorthand, usage) 43 | } 44 | 45 | // StringVar defines a string flag with specified name, default value, and usage string. 46 | // The argument p points to a string variable in which to store the value of the flag. 47 | func StringVar(p *string, name string, value string, usage string) { 48 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 49 | } 50 | 51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 52 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // String defines a string flag with specified name, default value, and usage string. 57 | // The return value is the address of a string variable that stores the value of the flag. 58 | func (f *FlagSet) String(name string, value string, usage string) *string { 59 | p := new(string) 60 | f.StringVarP(p, name, "", value, usage) 61 | return p 62 | } 63 | 64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 66 | p := new(string) 67 | f.StringVarP(p, name, shorthand, value, usage) 68 | return p 69 | } 70 | 71 | // String defines a string flag with specified name, default value, and usage string. 72 | // The return value is the address of a string variable that stores the value of the flag. 73 | func String(name string, value string, usage string) *string { 74 | return CommandLine.StringP(name, "", value, usage) 75 | } 76 | 77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 78 | func StringP(name, shorthand string, value string, usage string) *string { 79 | return CommandLine.StringP(name, shorthand, value, usage) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint Value 6 | type uintValue uint 7 | 8 | func newUintValue(val uint, p *uint) *uintValue { 9 | *p = val 10 | return (*uintValue)(p) 11 | } 12 | 13 | func (i *uintValue) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uintValue(v) 16 | return err 17 | } 18 | 19 | func (i *uintValue) Type() string { 20 | return "uint" 21 | } 22 | 23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uintConv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 0) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint(v), nil 31 | } 32 | 33 | // GetUint return the uint value of a flag with the given name 34 | func (f *FlagSet) GetUint(name string) (uint, error) { 35 | val, err := f.getFlagType(name, "uint", uintConv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint), nil 40 | } 41 | 42 | // UintVar defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 45 | f.VarP(newUintValue(value, p), name, "", usage) 46 | } 47 | 48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 50 | f.VarP(newUintValue(value, p), name, shorthand, usage) 51 | } 52 | 53 | // UintVar defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func UintVar(p *uint, name string, value uint, usage string) { 56 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 57 | } 58 | 59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 67 | p := new(uint) 68 | f.UintVarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 74 | p := new(uint) 75 | f.UintVarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint(name string, value uint, usage string) *uint { 82 | return CommandLine.UintP(name, "", value, usage) 83 | } 84 | 85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 86 | func UintP(name, shorthand string, value uint, usage string) *uint { 87 | return CommandLine.UintP(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint16 value 6 | type uint16Value uint16 7 | 8 | func newUint16Value(val uint16, p *uint16) *uint16Value { 9 | *p = val 10 | return (*uint16Value)(p) 11 | } 12 | 13 | func (i *uint16Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 16) 15 | *i = uint16Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint16Value) Type() string { 20 | return "uint16" 21 | } 22 | 23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint16(v), nil 31 | } 32 | 33 | // GetUint16 return the uint16 value of a flag with the given name 34 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 35 | val, err := f.getFlagType(name, "uint16", uint16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint16), nil 40 | } 41 | 42 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 45 | f.VarP(newUint16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 50 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint16 defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 67 | p := new(uint16) 68 | f.Uint16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 74 | p := new(uint16) 75 | f.Uint16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint16 defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint16(name string, value uint16, usage string) *uint16 { 82 | return CommandLine.Uint16P(name, "", value, usage) 83 | } 84 | 85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 87 | return CommandLine.Uint16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint32 value 6 | type uint32Value uint32 7 | 8 | func newUint32Value(val uint32, p *uint32) *uint32Value { 9 | *p = val 10 | return (*uint32Value)(p) 11 | } 12 | 13 | func (i *uint32Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 32) 15 | *i = uint32Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint32Value) Type() string { 20 | return "uint32" 21 | } 22 | 23 | func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint32(v), nil 31 | } 32 | 33 | // GetUint32 return the uint32 value of a flag with the given name 34 | func (f *FlagSet) GetUint32(name string) (uint32, error) { 35 | val, err := f.getFlagType(name, "uint32", uint32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint32), nil 40 | } 41 | 42 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { 45 | f.VarP(newUint32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 50 | f.VarP(newUint32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint32 variable in which to store the value of the flag. 55 | func Uint32Var(p *uint32, name string, value uint32, usage string) { 56 | CommandLine.VarP(newUint32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 61 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint32 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { 67 | p := new(uint32) 68 | f.Uint32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 74 | p := new(uint32) 75 | f.Uint32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint32 variable that stores the value of the flag. 81 | func Uint32(name string, value uint32, usage string) *uint32 { 82 | return CommandLine.Uint32P(name, "", value, usage) 83 | } 84 | 85 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 87 | return CommandLine.Uint32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint64 Value 6 | type uint64Value uint64 7 | 8 | func newUint64Value(val uint64, p *uint64) *uint64Value { 9 | *p = val 10 | return (*uint64Value)(p) 11 | } 12 | 13 | func (i *uint64Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uint64Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint64Value) Type() string { 20 | return "uint64" 21 | } 22 | 23 | func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint64Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 64) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint64(v), nil 31 | } 32 | 33 | // GetUint64 return the uint64 value of a flag with the given name 34 | func (f *FlagSet) GetUint64(name string) (uint64, error) { 35 | val, err := f.getFlagType(name, "uint64", uint64Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint64), nil 40 | } 41 | 42 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint64 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { 45 | f.VarP(newUint64Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 50 | f.VarP(newUint64Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint64 variable in which to store the value of the flag. 55 | func Uint64Var(p *uint64, name string, value uint64, usage string) { 56 | CommandLine.VarP(newUint64Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 61 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint64 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { 67 | p := new(uint64) 68 | f.Uint64VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 74 | p := new(uint64) 75 | f.Uint64VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint64 variable that stores the value of the flag. 81 | func Uint64(name string, value uint64, usage string) *uint64 { 82 | return CommandLine.Uint64P(name, "", value, usage) 83 | } 84 | 85 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 87 | return CommandLine.Uint64P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint8 Value 6 | type uint8Value uint8 7 | 8 | func newUint8Value(val uint8, p *uint8) *uint8Value { 9 | *p = val 10 | return (*uint8Value)(p) 11 | } 12 | 13 | func (i *uint8Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 8) 15 | *i = uint8Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint8Value) Type() string { 20 | return "uint8" 21 | } 22 | 23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint8(v), nil 31 | } 32 | 33 | // GetUint8 return the uint8 value of a flag with the given name 34 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 35 | val, err := f.getFlagType(name, "uint8", uint8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint8), nil 40 | } 41 | 42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 45 | f.VarP(newUint8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 50 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint8 variable in which to store the value of the flag. 55 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint8 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 67 | p := new(uint8) 68 | f.Uint8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 74 | p := new(uint8) 75 | f.Uint8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint8 variable that stores the value of the flag. 81 | func Uint8(name string, value uint8, usage string) *uint8 { 82 | return CommandLine.Uint8P(name, "", value, usage) 83 | } 84 | 85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 87 | return CommandLine.Uint8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/verify/all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | ROOT=$(dirname "${BASH_SOURCE}")/.. 8 | 9 | # Some useful colors. 10 | if [[ -z "${color_start-}" ]]; then 11 | declare -r color_start="\033[" 12 | declare -r color_red="${color_start}0;31m" 13 | declare -r color_yellow="${color_start}0;33m" 14 | declare -r color_green="${color_start}0;32m" 15 | declare -r color_norm="${color_start}0m" 16 | fi 17 | 18 | SILENT=true 19 | 20 | function is-excluded { 21 | for e in $EXCLUDE; do 22 | if [[ $1 -ef ${BASH_SOURCE} ]]; then 23 | return 24 | fi 25 | if [[ $1 -ef "$ROOT/hack/$e" ]]; then 26 | return 27 | fi 28 | done 29 | return 1 30 | } 31 | 32 | while getopts ":v" opt; do 33 | case $opt in 34 | v) 35 | SILENT=false 36 | ;; 37 | \?) 38 | echo "Invalid flag: -$OPTARG" >&2 39 | exit 1 40 | ;; 41 | esac 42 | done 43 | 44 | if $SILENT ; then 45 | echo "Running in the silent mode, run with -v if you want to see script logs." 46 | fi 47 | 48 | EXCLUDE="all.sh" 49 | 50 | ret=0 51 | for t in `ls $ROOT/verify/*.sh` 52 | do 53 | if is-excluded $t ; then 54 | echo "Skipping $t" 55 | continue 56 | fi 57 | if $SILENT ; then 58 | echo -e "Verifying $t" 59 | if bash "$t" &> /dev/null; then 60 | echo -e "${color_green}SUCCESS${color_norm}" 61 | else 62 | echo -e "${color_red}FAILED${color_norm}" 63 | ret=1 64 | fi 65 | else 66 | bash "$t" || ret=1 67 | fi 68 | done 69 | exit $ret 70 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/verify/gofmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | ROOT=$(dirname "${BASH_SOURCE}")/.. 8 | 9 | pushd "${ROOT}" > /dev/null 10 | 11 | GOFMT=${GOFMT:-"gofmt"} 12 | bad_files=$(find . -name '*.go' | xargs $GOFMT -s -l) 13 | if [[ -n "${bad_files}" ]]; then 14 | echo "!!! '$GOFMT' needs to be run on the following files: " 15 | echo "${bad_files}" 16 | exit 1 17 | fi 18 | 19 | # ex: ts=2 sw=2 et filetype=sh 20 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/verify/golint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ROOT=$(dirname "${BASH_SOURCE}")/.. 4 | GOLINT=${GOLINT:-"golint"} 5 | 6 | pushd "${ROOT}" > /dev/null 7 | bad_files=$($GOLINT -min_confidence=0.9 ./...) 8 | if [[ -n "${bad_files}" ]]; then 9 | echo "!!! '$GOLINT' problems: " 10 | echo "${bad_files}" 11 | exit 1 12 | fi 13 | popd > /dev/null 14 | 15 | # ex: ts=2 sw=2 et filetype=sh 16 | --------------------------------------------------------------------------------