Browse Source

cleaning shop

bryanl 3 years ago
parent
commit
6fae0d2185
100 changed files with 0 additions and 13564 deletions
  1. 0
    7
      .gitignore
  2. 0
    12
      .travis.yml
  3. 0
    16
      Examples/cloud-config.yml
  4. 0
    44
      Examples/start_cluster.sh
  5. 0
    40
      Godeps/Godeps.json
  6. 0
    5
      Godeps/Readme
  7. 0
    2
      Godeps/_workspace/.gitignore
  8. 0
    6
      Godeps/_workspace/src/github.com/codegangsta/cli/.travis.yml
  9. 0
    21
      Godeps/_workspace/src/github.com/codegangsta/cli/LICENSE
  10. 0
    306
      Godeps/_workspace/src/github.com/codegangsta/cli/README.md
  11. 0
    298
      Godeps/_workspace/src/github.com/codegangsta/cli/app.go
  12. 0
    719
      Godeps/_workspace/src/github.com/codegangsta/cli/app_test.go
  13. 0
    13
      Godeps/_workspace/src/github.com/codegangsta/cli/autocomplete/bash_autocomplete
  14. 0
    5
      Godeps/_workspace/src/github.com/codegangsta/cli/autocomplete/zsh_autocomplete
  15. 0
    19
      Godeps/_workspace/src/github.com/codegangsta/cli/cli.go
  16. 0
    100
      Godeps/_workspace/src/github.com/codegangsta/cli/cli_test.go
  17. 0
    184
      Godeps/_workspace/src/github.com/codegangsta/cli/command.go
  18. 0
    49
      Godeps/_workspace/src/github.com/codegangsta/cli/command_test.go
  19. 0
    376
      Godeps/_workspace/src/github.com/codegangsta/cli/context.go
  20. 0
    115
      Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go
  21. 0
    460
      Godeps/_workspace/src/github.com/codegangsta/cli/flag.go
  22. 0
    742
      Godeps/_workspace/src/github.com/codegangsta/cli/flag_test.go
  23. 0
    235
      Godeps/_workspace/src/github.com/codegangsta/cli/help.go
  24. 0
    22
      Godeps/_workspace/src/github.com/codegangsta/cli/help_test.go
  25. 0
    19
      Godeps/_workspace/src/github.com/codegangsta/cli/helpers_test.go
  26. 0
    6
      Godeps/_workspace/src/github.com/digitalocean/godo/.travis.yml
  27. 0
    23
      Godeps/_workspace/src/github.com/digitalocean/godo/CONTRIBUTING.md
  28. 0
    55
      Godeps/_workspace/src/github.com/digitalocean/godo/LICENSE.txt
  29. 0
    136
      Godeps/_workspace/src/github.com/digitalocean/godo/README.md
  30. 0
    50
      Godeps/_workspace/src/github.com/digitalocean/godo/account.go
  31. 0
    55
      Godeps/_workspace/src/github.com/digitalocean/godo/account_test.go
  32. 0
    96
      Godeps/_workspace/src/github.com/digitalocean/godo/action.go
  33. 0
    136
      Godeps/_workspace/src/github.com/digitalocean/godo/action_test.go
  34. 0
    346
      Godeps/_workspace/src/github.com/digitalocean/godo/cover.out
  35. 0
    2
      Godeps/_workspace/src/github.com/digitalocean/godo/doc.go
  36. 0
    270
      Godeps/_workspace/src/github.com/digitalocean/godo/domains.go
  37. 0
    340
      Godeps/_workspace/src/github.com/digitalocean/godo/domains_test.go
  38. 0
    215
      Godeps/_workspace/src/github.com/digitalocean/godo/droplet_actions.go
  39. 0
    631
      Godeps/_workspace/src/github.com/digitalocean/godo/droplet_actions_test.go
  40. 0
    371
      Godeps/_workspace/src/github.com/digitalocean/godo/droplets.go
  41. 0
    371
      Godeps/_workspace/src/github.com/digitalocean/godo/droplets_test.go
  42. 0
    337
      Godeps/_workspace/src/github.com/digitalocean/godo/godo.go
  43. 0
    455
      Godeps/_workspace/src/github.com/digitalocean/godo/godo_test.go
  44. 0
    55
      Godeps/_workspace/src/github.com/digitalocean/godo/image_actions.go
  45. 0
    62
      Godeps/_workspace/src/github.com/digitalocean/godo/image_actions_test.go
  46. 0
    173
      Godeps/_workspace/src/github.com/digitalocean/godo/images.go
  47. 0
    261
      Godeps/_workspace/src/github.com/digitalocean/godo/images_test.go
  48. 0
    186
      Godeps/_workspace/src/github.com/digitalocean/godo/keys.go
  49. 0
    265
      Godeps/_workspace/src/github.com/digitalocean/godo/keys_test.go
  50. 0
    86
      Godeps/_workspace/src/github.com/digitalocean/godo/links.go
  51. 0
    176
      Godeps/_workspace/src/github.com/digitalocean/godo/links_test.go
  52. 0
    63
      Godeps/_workspace/src/github.com/digitalocean/godo/regions.go
  53. 0
    91
      Godeps/_workspace/src/github.com/digitalocean/godo/regions_test.go
  54. 0
    63
      Godeps/_workspace/src/github.com/digitalocean/godo/sizes.go
  55. 0
    96
      Godeps/_workspace/src/github.com/digitalocean/godo/sizes_test.go
  56. 0
    83
      Godeps/_workspace/src/github.com/digitalocean/godo/strings.go
  57. 0
    35
      Godeps/_workspace/src/github.com/digitalocean/godo/timestamp.go
  58. 0
    176
      Godeps/_workspace/src/github.com/digitalocean/godo/timestamp_test.go
  59. 0
    47
      Godeps/_workspace/src/github.com/digitalocean/godo/util/droplet.go
  60. 0
    26
      Godeps/_workspace/src/github.com/digitalocean/godo/util/droplet_test.go
  61. 0
    307
      Godeps/_workspace/src/github.com/google/go-querystring/query/encode.go
  62. 0
    286
      Godeps/_workspace/src/github.com/google/go-querystring/query/encode_test.go
  63. 0
    1
      Godeps/_workspace/src/github.com/tent/http-link-go/.gitignore
  64. 0
    6
      Godeps/_workspace/src/github.com/tent/http-link-go/.travis.yml
  65. 0
    27
      Godeps/_workspace/src/github.com/tent/http-link-go/LICENSE
  66. 0
    12
      Godeps/_workspace/src/github.com/tent/http-link-go/README.md
  67. 0
    185
      Godeps/_workspace/src/github.com/tent/http-link-go/link.go
  68. 0
    67
      Godeps/_workspace/src/github.com/tent/http-link-go/link_test.go
  69. 0
    432
      Godeps/_workspace/src/golang.org/x/net/context/context.go
  70. 0
    553
      Godeps/_workspace/src/golang.org/x/net/context/context_test.go
  71. 0
    26
      Godeps/_workspace/src/golang.org/x/net/context/withtimeout_test.go
  72. 0
    14
      Godeps/_workspace/src/golang.org/x/oauth2/.travis.yml
  73. 0
    3
      Godeps/_workspace/src/golang.org/x/oauth2/AUTHORS
  74. 0
    31
      Godeps/_workspace/src/golang.org/x/oauth2/CONTRIBUTING.md
  75. 0
    3
      Godeps/_workspace/src/golang.org/x/oauth2/CONTRIBUTORS
  76. 0
    27
      Godeps/_workspace/src/golang.org/x/oauth2/LICENSE
  77. 0
    64
      Godeps/_workspace/src/golang.org/x/oauth2/README.md
  78. 0
    25
      Godeps/_workspace/src/golang.org/x/oauth2/client_appengine.go
  79. 0
    112
      Godeps/_workspace/src/golang.org/x/oauth2/clientcredentials/clientcredentials.go
  80. 0
    96
      Godeps/_workspace/src/golang.org/x/oauth2/clientcredentials/clientcredentials_test.go
  81. 0
    45
      Godeps/_workspace/src/golang.org/x/oauth2/example_test.go
  82. 0
    16
      Godeps/_workspace/src/golang.org/x/oauth2/facebook/facebook.go
  83. 0
    16
      Godeps/_workspace/src/golang.org/x/oauth2/github/github.go
  84. 0
    83
      Godeps/_workspace/src/golang.org/x/oauth2/google/appengine.go
  85. 0
    13
      Godeps/_workspace/src/golang.org/x/oauth2/google/appengine_hook.go
  86. 0
    154
      Godeps/_workspace/src/golang.org/x/oauth2/google/default.go
  87. 0
    150
      Godeps/_workspace/src/golang.org/x/oauth2/google/example_test.go
  88. 0
    145
      Godeps/_workspace/src/golang.org/x/oauth2/google/google.go
  89. 0
    67
      Godeps/_workspace/src/golang.org/x/oauth2/google/google_test.go
  90. 0
    168
      Godeps/_workspace/src/golang.org/x/oauth2/google/sdk.go
  91. 0
    46
      Godeps/_workspace/src/golang.org/x/oauth2/google/sdk_test.go
  92. 0
    122
      Godeps/_workspace/src/golang.org/x/oauth2/google/testdata/gcloud/credentials
  93. 0
    2
      Godeps/_workspace/src/golang.org/x/oauth2/google/testdata/gcloud/properties
  94. 0
    76
      Godeps/_workspace/src/golang.org/x/oauth2/internal/oauth2.go
  95. 0
    62
      Godeps/_workspace/src/golang.org/x/oauth2/internal/oauth2_test.go
  96. 0
    213
      Godeps/_workspace/src/golang.org/x/oauth2/internal/token.go
  97. 0
    28
      Godeps/_workspace/src/golang.org/x/oauth2/internal/token_test.go
  98. 0
    67
      Godeps/_workspace/src/golang.org/x/oauth2/internal/transport.go
  99. 0
    160
      Godeps/_workspace/src/golang.org/x/oauth2/jws/jws.go
  100. 0
    0
      Godeps/_workspace/src/golang.org/x/oauth2/jwt/example_test.go

+ 0
- 7
.gitignore View File

@@ -1,7 +0,0 @@
1
-.DS_Store
2
-bin*
3
-.deps
4
-doctl
5
-releaselog*
6
-.idea*
7
-doctl.iml

+ 0
- 12
.travis.yml View File

@@ -1,12 +0,0 @@
1
----
2
-language: go
3
-
4
-go:
5
-  - 1.4.2
6
-  - tip
7
-
8
-install:
9
-  - export PATH=$PATH:$HOME/gopath/bin
10
-
11
-script:
12
-  - make test

+ 0
- 16
Examples/cloud-config.yml View File

@@ -1,16 +0,0 @@
1
-#cloud-config
2
-
3
-coreos:
4
-  etcd:
5
-    discovery: DISCOVERY_URL
6
-    addr: $private_ipv4:4001
7
-    peer-addr: $private_ipv4:7001
8
-  fleet:
9
-    public-ip: $private_ipv4   # used for fleetctl ssh command
10
-  units:
11
-    - name: etcd.service
12
-      command: start
13
-    - name: fleet.service
14
-      command: start
15
-    - name: docker.service
16
-      command: start

+ 0
- 44
Examples/start_cluster.sh View File

@@ -1,44 +0,0 @@
1
-#/bin/bash
2
-
3
-if [[ $# -lt 3 ]]; then 
4
-	echo "Usage:"
5
-	echo "\tstart_cluster.sh <domain> <region> <droplet_count>"
6
-	exit 64
7
-fi
8
-
9
-DOMAIN=$1
10
-REGION=$2
11
-COUNT=$3
12
-
13
-DISCOVERYURL=`curl -s -w "\n" https://discovery.etcd.io/new`
14
-USERDATA=`cat cloud-config.yml| sed -e "s#DISCOVERY_URL#${DISCOVERYURL}#"`
15
-MAX_ID=`echo $3-1 | bc`
16
-
17
-echo "Starting CoreOS cluster ---"
18
-echo "--- DISCOVERYURL: $DISCOVERYURL"
19
-echo "--- DOMAIN: $DOMAIN"
20
-echo "--- COUNT: $COUNT"
21
-echo "--- REGION $REGION"
22
-echo "--- USERDATA ---"
23
-echo $USERDATA
24
-echo "---"
25
-
26
-for i in `seq 0 ${MAX_ID}`;
27
-do
28
-	HOST="core${i}"
29
-
30
-	echo "Creating ${HOST}..."
31
-
32
-	./doctl droplet create \
33
-	--domain $DOMAIN \
34
-	--image 5914637 \
35
-	--size 1gb \
36
-	--region $REGION \
37
-	--ssh-keys Work,Home \
38
-	--private-networking \
39
-	--add-region \
40
-	--user-data="${USERDATA}" \
41
-	$HOST
42
-
43
-    echo "Done."
44
-done  

+ 0
- 40
Godeps/Godeps.json View File

@@ -1,40 +0,0 @@
1
-{
2
-	"ImportPath": "github.com/digitalocean/doctl",
3
-	"GoVersion": "go1.4.2",
4
-	"Packages": [
5
-		"./..."
6
-	],
7
-	"Deps": [
8
-		{
9
-			"ImportPath": "github.com/codegangsta/cli",
10
-			"Comment": "1.2.0-111-g854c521",
11
-			"Rev": "854c52192c709766187afe5891a755bc97f82c38"
12
-		},
13
-		{
14
-			"ImportPath": "github.com/digitalocean/godo",
15
-			"Comment": "0.8.0-6-ga503f0a",
16
-			"Rev": "a503f0ad74553f4e879e73e40b52acb4b6e9732c"
17
-		},
18
-		{
19
-			"ImportPath": "github.com/google/go-querystring/query",
20
-			"Rev": "547ef5ac979778feb2f760cdb5f4eae1a2207b86"
21
-		},
22
-		{
23
-			"ImportPath": "github.com/tent/http-link-go",
24
-			"Rev": "ac974c61c2f990f4115b119354b5e0b47550e888"
25
-		},
26
-		{
27
-			"ImportPath": "golang.org/x/net/context",
28
-			"Comment": "null-240",
29
-			"Rev": "937a34c9de13c766c814510f76bca091dee06028"
30
-		},
31
-		{
32
-			"ImportPath": "golang.org/x/oauth2",
33
-			"Rev": "b5adcc2dcdf009d0391547edc6ecbaff889f5bb9"
34
-		},
35
-		{
36
-			"ImportPath": "gopkg.in/yaml.v1",
37
-			"Rev": "9f9df34309c04878acc86042b16630b0f696e1de"
38
-		}
39
-	]
40
-}

+ 0
- 5
Godeps/Readme View File

@@ -1,5 +0,0 @@
1
-This directory tree is generated automatically by godep.
2
-
3
-Please do not edit.
4
-
5
-See https://github.com/tools/godep for more information.

+ 0
- 2
Godeps/_workspace/.gitignore View File

@@ -1,2 +0,0 @@
1
-/pkg
2
-/bin

+ 0
- 6
Godeps/_workspace/src/github.com/codegangsta/cli/.travis.yml View File

@@ -1,6 +0,0 @@
1
-language: go
2
-go: 1.1
3
-
4
-script:
5
-- go vet ./...
6
-- go test -v ./...

+ 0
- 21
Godeps/_workspace/src/github.com/codegangsta/cli/LICENSE View File

@@ -1,21 +0,0 @@
1
-Copyright (C) 2013 Jeremy Saenz
2
-All Rights Reserved.
3
-
4
-MIT LICENSE
5
-
6
-Permission is hereby granted, free of charge, to any person obtaining a copy of
7
-this software and associated documentation files (the "Software"), to deal in
8
-the Software without restriction, including without limitation the rights to
9
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
-the Software, and to permit persons to whom the Software is furnished to do so,
11
-subject to the following conditions:
12
-
13
-The above copyright notice and this permission notice shall be included in all
14
-copies or substantial portions of the Software.
15
-
16
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 0
- 306
Godeps/_workspace/src/github.com/codegangsta/cli/README.md View File

@@ -1,306 +0,0 @@
1
-[![Build Status](https://travis-ci.org/codegangsta/cli.png?branch=master)](https://travis-ci.org/codegangsta/cli)
2
-
3
-# cli.go
4
-cli.go is simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line applications in an expressive way.
5
-
6
-You can view the API docs here:
7
-http://godoc.org/github.com/codegangsta/cli
8
-
9
-## Overview
10
-Command line apps are usually so tiny that there is absolutely no reason why your code should *not* be self-documenting. Things like generating help text and parsing command flags/options should not hinder productivity when writing a command line app.
11
-
12
-**This is where cli.go comes into play.** cli.go makes command line programming fun, organized, and expressive!
13
-
14
-## Installation
15
-Make sure you have a working Go environment (go 1.1+ is *required*). [See the install instructions](http://golang.org/doc/install.html).
16
-
17
-To install `cli.go`, simply run:
18
-```
19
-$ go get github.com/codegangsta/cli
20
-```
21
-
22
-Make sure your `PATH` includes to the `$GOPATH/bin` directory so your commands can be easily used:
23
-```
24
-export PATH=$PATH:$GOPATH/bin
25
-```
26
-
27
-## Getting Started
28
-One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`. 
29
-
30
-``` go
31
-package main
32
-
33
-import (
34
-  "os"
35
-  "github.com/codegangsta/cli"
36
-)
37
-
38
-func main() {
39
-  cli.NewApp().Run(os.Args)
40
-}
41
-```
42
-
43
-This app will run and show help text, but is not very useful. Let's give an action to execute and some help documentation:
44
-
45
-``` go
46
-package main
47
-
48
-import (
49
-  "os"
50
-  "github.com/codegangsta/cli"
51
-)
52
-
53
-func main() {
54
-  app := cli.NewApp()
55
-  app.Name = "boom"
56
-  app.Usage = "make an explosive entrance"
57
-  app.Action = func(c *cli.Context) {
58
-    println("boom! I say!")
59
-  }
60
-  
61
-  app.Run(os.Args)
62
-}
63
-```
64
-
65
-Running this already gives you a ton of functionality, plus support for things like subcommands and flags, which are covered below.
66
-
67
-## Example
68
-
69
-Being a programmer can be a lonely job. Thankfully by the power of automation that is not the case! Let's create a greeter app to fend off our demons of loneliness!
70
-
71
-Start by creating a directory named `greet`, and within it, add a file, `greet.go` with the following code in it:
72
-
73
-``` go
74
-package main
75
-
76
-import (
77
-  "os"
78
-  "github.com/codegangsta/cli"
79
-)
80
-
81
-func main() {
82
-  app := cli.NewApp()
83
-  app.Name = "greet"
84
-  app.Usage = "fight the loneliness!"
85
-  app.Action = func(c *cli.Context) {
86
-    println("Hello friend!")
87
-  }
88
-
89
-  app.Run(os.Args)
90
-}
91
-```
92
-
93
-Install our command to the `$GOPATH/bin` directory:
94
-
95
-```
96
-$ go install
97
-```
98
-
99
-Finally run our new command:
100
-
101
-```
102
-$ greet
103
-Hello friend!
104
-```
105
-
106
-cli.go also generates some bitchass help text:
107
-```
108
-$ greet help
109
-NAME:
110
-    greet - fight the loneliness!
111
-
112
-USAGE:
113
-    greet [global options] command [command options] [arguments...]
114
-
115
-VERSION:
116
-    0.0.0
117
-
118
-COMMANDS:
119
-    help, h  Shows a list of commands or help for one command
120
-
121
-GLOBAL OPTIONS
122
-    --version	Shows version information
123
-```
124
-
125
-### Arguments
126
-You can lookup arguments by calling the `Args` function on `cli.Context`.
127
-
128
-``` go
129
-...
130
-app.Action = func(c *cli.Context) {
131
-  println("Hello", c.Args()[0])
132
-}
133
-...
134
-```
135
-
136
-### Flags
137
-Setting and querying flags is simple.
138
-``` go
139
-...
140
-app.Flags = []cli.Flag {
141
-  cli.StringFlag{
142
-    Name: "lang",
143
-    Value: "english",
144
-    Usage: "language for the greeting",
145
-  },
146
-}
147
-app.Action = func(c *cli.Context) {
148
-  name := "someone"
149
-  if len(c.Args()) > 0 {
150
-    name = c.Args()[0]
151
-  }
152
-  if c.String("lang") == "spanish" {
153
-    println("Hola", name)
154
-  } else {
155
-    println("Hello", name)
156
-  }
157
-}
158
-...
159
-```
160
-
161
-#### Alternate Names
162
-
163
-You can set alternate (or short) names for flags by providing a comma-delimited list for the `Name`. e.g.
164
-
165
-``` go
166
-app.Flags = []cli.Flag {
167
-  cli.StringFlag{
168
-    Name: "lang, l",
169
-    Value: "english",
170
-    Usage: "language for the greeting",
171
-  },
172
-}
173
-```
174
-
175
-That flag can then be set with `--lang spanish` or `-l spanish`. Note that giving two different forms of the same flag in the same command invocation is an error.
176
-
177
-#### Values from the Environment
178
-
179
-You can also have the default value set from the environment via `EnvVar`.  e.g.
180
-
181
-``` go
182
-app.Flags = []cli.Flag {
183
-  cli.StringFlag{
184
-    Name: "lang, l",
185
-    Value: "english",
186
-    Usage: "language for the greeting",
187
-    EnvVar: "APP_LANG",
188
-  },
189
-}
190
-```
191
-
192
-The `EnvVar` may also be given as a comma-delimited "cascade", where the first environment variable that resolves is used as the default.
193
-
194
-``` go
195
-app.Flags = []cli.Flag {
196
-  cli.StringFlag{
197
-    Name: "lang, l",
198
-    Value: "english",
199
-    Usage: "language for the greeting",
200
-    EnvVar: "LEGACY_COMPAT_LANG,APP_LANG,LANG",
201
-  },
202
-}
203
-```
204
-
205
-### Subcommands
206
-
207
-Subcommands can be defined for a more git-like command line app.
208
-```go
209
-...
210
-app.Commands = []cli.Command{
211
-  {
212
-    Name:      "add",
213
-    Aliases:     []string{"a"},
214
-    Usage:     "add a task to the list",
215
-    Action: func(c *cli.Context) {
216
-      println("added task: ", c.Args().First())
217
-    },
218
-  },
219
-  {
220
-    Name:      "complete",
221
-    Aliases:     []string{"c"},
222
-    Usage:     "complete a task on the list",
223
-    Action: func(c *cli.Context) {
224
-      println("completed task: ", c.Args().First())
225
-    },
226
-  },
227
-  {
228
-    Name:      "template",
229
-    Aliases:     []string{"r"},
230
-    Usage:     "options for task templates",
231
-    Subcommands: []cli.Command{
232
-      {
233
-        Name:  "add",
234
-        Usage: "add a new template",
235
-        Action: func(c *cli.Context) {
236
-            println("new task template: ", c.Args().First())
237
-        },
238
-      },
239
-      {
240
-        Name:  "remove",
241
-        Usage: "remove an existing template",
242
-        Action: func(c *cli.Context) {
243
-          println("removed task template: ", c.Args().First())
244
-        },
245
-      },
246
-    },
247
-  },
248
-}
249
-...
250
-```
251
-
252
-### Bash Completion
253
-
254
-You can enable completion commands by setting the `EnableBashCompletion`
255
-flag on the `App` object.  By default, this setting will only auto-complete to
256
-show an app's subcommands, but you can write your own completion methods for
257
-the App or its subcommands.
258
-```go
259
-...
260
-var tasks = []string{"cook", "clean", "laundry", "eat", "sleep", "code"}
261
-app := cli.NewApp()
262
-app.EnableBashCompletion = true
263
-app.Commands = []cli.Command{
264
-  {
265
-    Name:  "complete",
266
-    Aliases: []string{"c"},
267
-    Usage: "complete a task on the list",
268
-    Action: func(c *cli.Context) {
269
-       println("completed task: ", c.Args().First())
270
-    },
271
-    BashComplete: func(c *cli.Context) {
272
-      // This will complete if no args are passed
273
-      if len(c.Args()) > 0 {
274
-        return
275
-      }
276
-      for _, t := range tasks {
277
-        fmt.Println(t)
278
-      }
279
-    },
280
-  }
281
-}
282
-...
283
-```
284
-
285
-#### To Enable
286
-
287
-Source the `autocomplete/bash_autocomplete` file in your `.bashrc` file while
288
-setting the `PROG` variable to the name of your program:
289
-
290
-`PROG=myprogram source /.../cli/autocomplete/bash_autocomplete`
291
-
292
-#### To Distribute
293
-
294
-Copy and modify `autocomplete/bash_autocomplete` to use your program name
295
-rather than `$PROG` and have the user copy the file into
296
-`/etc/bash_completion.d/` (or automatically install it there if you are
297
-distributing a package). Alternatively you can just document that users should
298
-source the generic `autocomplete/bash_autocomplete` with `$PROG` set to your
299
-program name in their bash configuration.
300
-
301
-## Contribution Guidelines
302
-Feel free to put up a pull request to fix a bug or maybe add a feature. I will give it a code review and make sure that it does not break backwards compatibility. If I or any other collaborators agree that it is in line with the vision of the project, we will work with you to get the code into a mergeable state and merge it into the master branch.
303
-
304
-If you have contributed something significant to the project, I will most likely add you as a collaborator. As a collaborator you are given the ability to merge others pull requests. It is very important that new code does not break existing code, so be careful about what code you do choose to merge. If you have any questions feel free to link @codegangsta to the issue in question and we can review it together.
305
-
306
-If you feel like you have contributed to the project but have not yet been added as a collaborator, I probably forgot to add you. Hit @codegangsta up over email and we will get it figured out.

+ 0
- 298
Godeps/_workspace/src/github.com/codegangsta/cli/app.go View File

@@ -1,298 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"fmt"
5
-	"io"
6
-	"io/ioutil"
7
-	"os"
8
-	"time"
9
-)
10
-
11
-// App is the main structure of a cli application. It is recomended that
12
-// and app be created with the cli.NewApp() function
13
-type App struct {
14
-	// The name of the program. Defaults to os.Args[0]
15
-	Name string
16
-	// Description of the program.
17
-	Usage string
18
-	// Version of the program
19
-	Version string
20
-	// List of commands to execute
21
-	Commands []Command
22
-	// List of flags to parse
23
-	Flags []Flag
24
-	// Boolean to enable bash completion commands
25
-	EnableBashCompletion bool
26
-	// Boolean to hide built-in help command
27
-	HideHelp bool
28
-	// Boolean to hide built-in version flag
29
-	HideVersion bool
30
-	// An action to execute when the bash-completion flag is set
31
-	BashComplete func(context *Context)
32
-	// An action to execute before any subcommands are run, but after the context is ready
33
-	// If a non-nil error is returned, no subcommands are run
34
-	Before func(context *Context) error
35
-	// An action to execute after any subcommands are run, but after the subcommand has finished
36
-	// It is run even if Action() panics
37
-	After func(context *Context) error
38
-	// The action to execute when no subcommands are specified
39
-	Action func(context *Context)
40
-	// Execute this function if the proper command cannot be found
41
-	CommandNotFound func(context *Context, command string)
42
-	// Compilation date
43
-	Compiled time.Time
44
-	// List of all authors who contributed
45
-	Authors []Author
46
-	// Name of Author (Note: Use App.Authors, this is deprecated)
47
-	Author string
48
-	// Email of Author (Note: Use App.Authors, this is deprecated)
49
-	Email string
50
-	// Writer writer to write output to
51
-	Writer io.Writer
52
-}
53
-
54
-// Tries to find out when this binary was compiled.
55
-// Returns the current time if it fails to find it.
56
-func compileTime() time.Time {
57
-	info, err := os.Stat(os.Args[0])
58
-	if err != nil {
59
-		return time.Now()
60
-	}
61
-	return info.ModTime()
62
-}
63
-
64
-// Creates a new cli Application with some reasonable defaults for Name, Usage, Version and Action.
65
-func NewApp() *App {
66
-	return &App{
67
-		Name:         os.Args[0],
68
-		Usage:        "A new cli application",
69
-		Version:      "0.0.0",
70
-		BashComplete: DefaultAppComplete,
71
-		Action:       helpCommand.Action,
72
-		Compiled:     compileTime(),
73
-		Writer:       os.Stdout,
74
-	}
75
-}
76
-
77
-// Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
78
-func (a *App) Run(arguments []string) (err error) {
79
-	if a.Author != "" || a.Email != "" {
80
-		a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
81
-	}
82
-
83
-	// append help to commands
84
-	if a.Command(helpCommand.Name) == nil && !a.HideHelp {
85
-		a.Commands = append(a.Commands, helpCommand)
86
-		if (HelpFlag != BoolFlag{}) {
87
-			a.appendFlag(HelpFlag)
88
-		}
89
-	}
90
-
91
-	//append version/help flags
92
-	if a.EnableBashCompletion {
93
-		a.appendFlag(BashCompletionFlag)
94
-	}
95
-
96
-	if !a.HideVersion {
97
-		a.appendFlag(VersionFlag)
98
-	}
99
-
100
-	// parse flags
101
-	set := flagSet(a.Name, a.Flags)
102
-	set.SetOutput(ioutil.Discard)
103
-	err = set.Parse(arguments[1:])
104
-	nerr := normalizeFlags(a.Flags, set)
105
-	if nerr != nil {
106
-		fmt.Fprintln(a.Writer, nerr)
107
-		context := NewContext(a, set, nil)
108
-		ShowAppHelp(context)
109
-		fmt.Fprintln(a.Writer)
110
-		return nerr
111
-	}
112
-	context := NewContext(a, set, nil)
113
-
114
-	if err != nil {
115
-		fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
116
-		ShowAppHelp(context)
117
-		fmt.Fprintln(a.Writer)
118
-		return err
119
-	}
120
-
121
-	if checkCompletions(context) {
122
-		return nil
123
-	}
124
-
125
-	if checkHelp(context) {
126
-		return nil
127
-	}
128
-
129
-	if checkVersion(context) {
130
-		return nil
131
-	}
132
-
133
-	if a.After != nil {
134
-		defer func() {
135
-			// err is always nil here.
136
-			// There is a check to see if it is non-nil
137
-			// just few lines before.
138
-			err = a.After(context)
139
-		}()
140
-	}
141
-
142
-	if a.Before != nil {
143
-		err := a.Before(context)
144
-		if err != nil {
145
-			return err
146
-		}
147
-	}
148
-
149
-	args := context.Args()
150
-	if args.Present() {
151
-		name := args.First()
152
-		c := a.Command(name)
153
-		if c != nil {
154
-			return c.Run(context)
155
-		}
156
-	}
157
-
158
-	// Run default Action
159
-	a.Action(context)
160
-	return nil
161
-}
162
-
163
-// Another entry point to the cli app, takes care of passing arguments and error handling
164
-func (a *App) RunAndExitOnError() {
165
-	if err := a.Run(os.Args); err != nil {
166
-		fmt.Fprintln(os.Stderr, err)
167
-		os.Exit(1)
168
-	}
169
-}
170
-
171
-// Invokes the subcommand given the context, parses ctx.Args() to generate command-specific flags
172
-func (a *App) RunAsSubcommand(ctx *Context) (err error) {
173
-	// append help to commands
174
-	if len(a.Commands) > 0 {
175
-		if a.Command(helpCommand.Name) == nil && !a.HideHelp {
176
-			a.Commands = append(a.Commands, helpCommand)
177
-			if (HelpFlag != BoolFlag{}) {
178
-				a.appendFlag(HelpFlag)
179
-			}
180
-		}
181
-	}
182
-
183
-	// append flags
184
-	if a.EnableBashCompletion {
185
-		a.appendFlag(BashCompletionFlag)
186
-	}
187
-
188
-	// parse flags
189
-	set := flagSet(a.Name, a.Flags)
190
-	set.SetOutput(ioutil.Discard)
191
-	err = set.Parse(ctx.Args().Tail())
192
-	nerr := normalizeFlags(a.Flags, set)
193
-	context := NewContext(a, set, ctx)
194
-
195
-	if nerr != nil {
196
-		fmt.Fprintln(a.Writer, nerr)
197
-		if len(a.Commands) > 0 {
198
-			ShowSubcommandHelp(context)
199
-		} else {
200
-			ShowCommandHelp(ctx, context.Args().First())
201
-		}
202
-		fmt.Fprintln(a.Writer)
203
-		return nerr
204
-	}
205
-
206
-	if err != nil {
207
-		fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
208
-		ShowSubcommandHelp(context)
209
-		return err
210
-	}
211
-
212
-	if checkCompletions(context) {
213
-		return nil
214
-	}
215
-
216
-	if len(a.Commands) > 0 {
217
-		if checkSubcommandHelp(context) {
218
-			return nil
219
-		}
220
-	} else {
221
-		if checkCommandHelp(ctx, context.Args().First()) {
222
-			return nil
223
-		}
224
-	}
225
-
226
-	if a.After != nil {
227
-		defer func() {
228
-			// err is always nil here.
229
-			// There is a check to see if it is non-nil
230
-			// just few lines before.
231
-			err = a.After(context)
232
-		}()
233
-	}
234
-
235
-	if a.Before != nil {
236
-		err := a.Before(context)
237
-		if err != nil {
238
-			return err
239
-		}
240
-	}
241
-
242
-	args := context.Args()
243
-	if args.Present() {
244
-		name := args.First()
245
-		c := a.Command(name)
246
-		if c != nil {
247
-			return c.Run(context)
248
-		}
249
-	}
250
-
251
-	// Run default Action
252
-	a.Action(context)
253
-
254
-	return nil
255
-}
256
-
257
-// Returns the named command on App. Returns nil if the command does not exist
258
-func (a *App) Command(name string) *Command {
259
-	for _, c := range a.Commands {
260
-		if c.HasName(name) {
261
-			return &c
262
-		}
263
-	}
264
-
265
-	return nil
266
-}
267
-
268
-func (a *App) hasFlag(flag Flag) bool {
269
-	for _, f := range a.Flags {
270
-		if flag == f {
271
-			return true
272
-		}
273
-	}
274
-
275
-	return false
276
-}
277
-
278
-func (a *App) appendFlag(flag Flag) {
279
-	if !a.hasFlag(flag) {
280
-		a.Flags = append(a.Flags, flag)
281
-	}
282
-}
283
-
284
-// Author represents someone who has contributed to a cli project.
285
-type Author struct {
286
-	Name  string // The Authors name
287
-	Email string // The Authors email
288
-}
289
-
290
-// String makes Author comply to the Stringer interface, to allow an easy print in the templating process
291
-func (a Author) String() string {
292
-	e := ""
293
-	if a.Email != "" {
294
-		e = "<" + a.Email + "> "
295
-	}
296
-
297
-	return fmt.Sprintf("%v %v", a.Name, e)
298
-}

+ 0
- 719
Godeps/_workspace/src/github.com/codegangsta/cli/app_test.go View File

@@ -1,719 +0,0 @@
1
-package cli_test
2
-
3
-import (
4
-	"bytes"
5
-	"flag"
6
-	"fmt"
7
-	"io"
8
-	"os"
9
-	"strings"
10
-	"testing"
11
-
12
-	"github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli"
13
-)
14
-
15
-func ExampleApp() {
16
-	// set args for examples sake
17
-	os.Args = []string{"greet", "--name", "Jeremy"}
18
-
19
-	app := cli.NewApp()
20
-	app.Name = "greet"
21
-	app.Flags = []cli.Flag{
22
-		cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
23
-	}
24
-	app.Action = func(c *cli.Context) {
25
-		fmt.Printf("Hello %v\n", c.String("name"))
26
-	}
27
-	app.Author = "Harrison"
28
-	app.Email = "harrison@lolwut.com"
29
-	app.Authors = []cli.Author{cli.Author{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
30
-	app.Run(os.Args)
31
-	// Output:
32
-	// Hello Jeremy
33
-}
34
-
35
-func ExampleAppSubcommand() {
36
-	// set args for examples sake
37
-	os.Args = []string{"say", "hi", "english", "--name", "Jeremy"}
38
-	app := cli.NewApp()
39
-	app.Name = "say"
40
-	app.Commands = []cli.Command{
41
-		{
42
-			Name:        "hello",
43
-			Aliases:     []string{"hi"},
44
-			Usage:       "use it to see a description",
45
-			Description: "This is how we describe hello the function",
46
-			Subcommands: []cli.Command{
47
-				{
48
-					Name:        "english",
49
-					Aliases:     []string{"en"},
50
-					Usage:       "sends a greeting in english",
51
-					Description: "greets someone in english",
52
-					Flags: []cli.Flag{
53
-						cli.StringFlag{
54
-							Name:  "name",
55
-							Value: "Bob",
56
-							Usage: "Name of the person to greet",
57
-						},
58
-					},
59
-					Action: func(c *cli.Context) {
60
-						fmt.Println("Hello,", c.String("name"))
61
-					},
62
-				},
63
-			},
64
-		},
65
-	}
66
-
67
-	app.Run(os.Args)
68
-	// Output:
69
-	// Hello, Jeremy
70
-}
71
-
72
-func ExampleAppHelp() {
73
-	// set args for examples sake
74
-	os.Args = []string{"greet", "h", "describeit"}
75
-
76
-	app := cli.NewApp()
77
-	app.Name = "greet"
78
-	app.Flags = []cli.Flag{
79
-		cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
80
-	}
81
-	app.Commands = []cli.Command{
82
-		{
83
-			Name:        "describeit",
84
-			Aliases:     []string{"d"},
85
-			Usage:       "use it to see a description",
86
-			Description: "This is how we describe describeit the function",
87
-			Action: func(c *cli.Context) {
88
-				fmt.Printf("i like to describe things")
89
-			},
90
-		},
91
-	}
92
-	app.Run(os.Args)
93
-	// Output:
94
-	// NAME:
95
-	//    describeit - use it to see a description
96
-	//
97
-	// USAGE:
98
-	//    command describeit [arguments...]
99
-	//
100
-	// DESCRIPTION:
101
-	//    This is how we describe describeit the function
102
-}
103
-
104
-func ExampleAppBashComplete() {
105
-	// set args for examples sake
106
-	os.Args = []string{"greet", "--generate-bash-completion"}
107
-
108
-	app := cli.NewApp()
109
-	app.Name = "greet"
110
-	app.EnableBashCompletion = true
111
-	app.Commands = []cli.Command{
112
-		{
113
-			Name:        "describeit",
114
-			Aliases:     []string{"d"},
115
-			Usage:       "use it to see a description",
116
-			Description: "This is how we describe describeit the function",
117
-			Action: func(c *cli.Context) {
118
-				fmt.Printf("i like to describe things")
119
-			},
120
-		}, {
121
-			Name:        "next",
122
-			Usage:       "next example",
123
-			Description: "more stuff to see when generating bash completion",
124
-			Action: func(c *cli.Context) {
125
-				fmt.Printf("the next example")
126
-			},
127
-		},
128
-	}
129
-
130
-	app.Run(os.Args)
131
-	// Output:
132
-	// describeit
133
-	// d
134
-	// next
135
-	// help
136
-	// h
137
-}
138
-
139
-func TestApp_Run(t *testing.T) {
140
-	s := ""
141
-
142
-	app := cli.NewApp()
143
-	app.Action = func(c *cli.Context) {
144
-		s = s + c.Args().First()
145
-	}
146
-
147
-	err := app.Run([]string{"command", "foo"})
148
-	expect(t, err, nil)
149
-	err = app.Run([]string{"command", "bar"})
150
-	expect(t, err, nil)
151
-	expect(t, s, "foobar")
152
-}
153
-
154
-var commandAppTests = []struct {
155
-	name     string
156
-	expected bool
157
-}{
158
-	{"foobar", true},
159
-	{"batbaz", true},
160
-	{"b", true},
161
-	{"f", true},
162
-	{"bat", false},
163
-	{"nothing", false},
164
-}
165
-
166
-func TestApp_Command(t *testing.T) {
167
-	app := cli.NewApp()
168
-	fooCommand := cli.Command{Name: "foobar", Aliases: []string{"f"}}
169
-	batCommand := cli.Command{Name: "batbaz", Aliases: []string{"b"}}
170
-	app.Commands = []cli.Command{
171
-		fooCommand,
172
-		batCommand,
173
-	}
174
-
175
-	for _, test := range commandAppTests {
176
-		expect(t, app.Command(test.name) != nil, test.expected)
177
-	}
178
-}
179
-
180
-func TestApp_CommandWithArgBeforeFlags(t *testing.T) {
181
-	var parsedOption, firstArg string
182
-
183
-	app := cli.NewApp()
184
-	command := cli.Command{
185
-		Name: "cmd",
186
-		Flags: []cli.Flag{
187
-			cli.StringFlag{Name: "option", Value: "", Usage: "some option"},
188
-		},
189
-		Action: func(c *cli.Context) {
190
-			parsedOption = c.String("option")
191
-			firstArg = c.Args().First()
192
-		},
193
-	}
194
-	app.Commands = []cli.Command{command}
195
-
196
-	app.Run([]string{"", "cmd", "my-arg", "--option", "my-option"})
197
-
198
-	expect(t, parsedOption, "my-option")
199
-	expect(t, firstArg, "my-arg")
200
-}
201
-
202
-func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
203
-	var context *cli.Context
204
-
205
-	a := cli.NewApp()
206
-	a.Commands = []cli.Command{
207
-		{
208
-			Name: "foo",
209
-			Action: func(c *cli.Context) {
210
-				context = c
211
-			},
212
-			Flags: []cli.Flag{
213
-				cli.StringFlag{
214
-					Name:  "lang",
215
-					Value: "english",
216
-					Usage: "language for the greeting",
217
-				},
218
-			},
219
-			Before: func(_ *cli.Context) error { return nil },
220
-		},
221
-	}
222
-	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})
223
-
224
-	expect(t, context.Args().Get(0), "abcd")
225
-	expect(t, context.String("lang"), "spanish")
226
-}
227
-
228
-func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) {
229
-	var parsedOption string
230
-	var args []string
231
-
232
-	app := cli.NewApp()
233
-	command := cli.Command{
234
-		Name: "cmd",
235
-		Flags: []cli.Flag{
236
-			cli.StringFlag{Name: "option", Value: "", Usage: "some option"},
237
-		},
238
-		Action: func(c *cli.Context) {
239
-			parsedOption = c.String("option")
240
-			args = c.Args()
241
-		},
242
-	}
243
-	app.Commands = []cli.Command{command}
244
-
245
-	app.Run([]string{"", "cmd", "my-arg", "--option", "my-option", "--", "--notARealFlag"})
246
-
247
-	expect(t, parsedOption, "my-option")
248
-	expect(t, args[0], "my-arg")
249
-	expect(t, args[1], "--")
250
-	expect(t, args[2], "--notARealFlag")
251
-}
252
-
253
-func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
254
-	var args []string
255
-
256
-	app := cli.NewApp()
257
-	command := cli.Command{
258
-		Name: "cmd",
259
-		Action: func(c *cli.Context) {
260
-			args = c.Args()
261
-		},
262
-	}
263
-	app.Commands = []cli.Command{command}
264
-
265
-	app.Run([]string{"", "cmd", "my-arg", "--", "notAFlagAtAll"})
266
-
267
-	expect(t, args[0], "my-arg")
268
-	expect(t, args[1], "--")
269
-	expect(t, args[2], "notAFlagAtAll")
270
-}
271
-
272
-func TestApp_Float64Flag(t *testing.T) {
273
-	var meters float64
274
-
275
-	app := cli.NewApp()
276
-	app.Flags = []cli.Flag{
277
-		cli.Float64Flag{Name: "height", Value: 1.5, Usage: "Set the height, in meters"},
278
-	}
279
-	app.Action = func(c *cli.Context) {
280
-		meters = c.Float64("height")
281
-	}
282
-
283
-	app.Run([]string{"", "--height", "1.93"})
284
-	expect(t, meters, 1.93)
285
-}
286
-
287
-func TestApp_ParseSliceFlags(t *testing.T) {
288
-	var parsedOption, firstArg string
289
-	var parsedIntSlice []int
290
-	var parsedStringSlice []string
291
-
292
-	app := cli.NewApp()
293
-	command := cli.Command{
294
-		Name: "cmd",
295
-		Flags: []cli.Flag{
296
-			cli.IntSliceFlag{Name: "p", Value: &cli.IntSlice{}, Usage: "set one or more ip addr"},
297
-			cli.StringSliceFlag{Name: "ip", Value: &cli.StringSlice{}, Usage: "set one or more ports to open"},
298
-		},
299
-		Action: func(c *cli.Context) {
300
-			parsedIntSlice = c.IntSlice("p")
301
-			parsedStringSlice = c.StringSlice("ip")
302
-			parsedOption = c.String("option")
303
-			firstArg = c.Args().First()
304
-		},
305
-	}
306
-	app.Commands = []cli.Command{command}
307
-
308
-	app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})
309
-
310
-	IntsEquals := func(a, b []int) bool {
311
-		if len(a) != len(b) {
312
-			return false
313
-		}
314
-		for i, v := range a {
315
-			if v != b[i] {
316
-				return false
317
-			}
318
-		}
319
-		return true
320
-	}
321
-
322
-	StrsEquals := func(a, b []string) bool {
323
-		if len(a) != len(b) {
324
-			return false
325
-		}
326
-		for i, v := range a {
327
-			if v != b[i] {
328
-				return false
329
-			}
330
-		}
331
-		return true
332
-	}
333
-	var expectedIntSlice = []int{22, 80}
334
-	var expectedStringSlice = []string{"8.8.8.8", "8.8.4.4"}
335
-
336
-	if !IntsEquals(parsedIntSlice, expectedIntSlice) {
337
-		t.Errorf("%v does not match %v", parsedIntSlice, expectedIntSlice)
338
-	}
339
-
340
-	if !StrsEquals(parsedStringSlice, expectedStringSlice) {
341
-		t.Errorf("%v does not match %v", parsedStringSlice, expectedStringSlice)
342
-	}
343
-}
344
-
345
-func TestApp_ParseSliceFlagsWithMissingValue(t *testing.T) {
346
-	var parsedIntSlice []int
347
-	var parsedStringSlice []string
348
-
349
-	app := cli.NewApp()
350
-	command := cli.Command{
351
-		Name: "cmd",
352
-		Flags: []cli.Flag{
353
-			cli.IntSliceFlag{Name: "a", Usage: "set numbers"},
354
-			cli.StringSliceFlag{Name: "str", Usage: "set strings"},
355
-		},
356
-		Action: func(c *cli.Context) {
357
-			parsedIntSlice = c.IntSlice("a")
358
-			parsedStringSlice = c.StringSlice("str")
359
-		},
360
-	}
361
-	app.Commands = []cli.Command{command}
362
-
363
-	app.Run([]string{"", "cmd", "my-arg", "-a", "2", "-str", "A"})
364
-
365
-	var expectedIntSlice = []int{2}
366
-	var expectedStringSlice = []string{"A"}
367
-
368
-	if parsedIntSlice[0] != expectedIntSlice[0] {
369
-		t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0])
370
-	}
371
-
372
-	if parsedStringSlice[0] != expectedStringSlice[0] {
373
-		t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0])
374
-	}
375
-}
376
-
377
-func TestApp_DefaultStdout(t *testing.T) {
378
-	app := cli.NewApp()
379
-
380
-	if app.Writer != os.Stdout {
381
-		t.Error("Default output writer not set.")
382
-	}
383
-}
384
-
385
-type mockWriter struct {
386
-	written []byte
387
-}
388
-
389
-func (fw *mockWriter) Write(p []byte) (n int, err error) {
390
-	if fw.written == nil {
391
-		fw.written = p
392
-	} else {
393
-		fw.written = append(fw.written, p...)
394
-	}
395
-
396
-	return len(p), nil
397
-}
398
-
399
-func (fw *mockWriter) GetWritten() (b []byte) {
400
-	return fw.written
401
-}
402
-
403
-func TestApp_SetStdout(t *testing.T) {
404
-	w := &mockWriter{}
405
-
406
-	app := cli.NewApp()
407
-	app.Name = "test"
408
-	app.Writer = w
409
-
410
-	err := app.Run([]string{"help"})
411
-
412
-	if err != nil {
413
-		t.Fatalf("Run error: %s", err)
414
-	}
415
-
416
-	if len(w.written) == 0 {
417
-		t.Error("App did not write output to desired writer.")
418
-	}
419
-}
420
-
421
-func TestApp_BeforeFunc(t *testing.T) {
422
-	beforeRun, subcommandRun := false, false
423
-	beforeError := fmt.Errorf("fail")
424
-	var err error
425
-
426
-	app := cli.NewApp()
427
-
428
-	app.Before = func(c *cli.Context) error {
429
-		beforeRun = true
430
-		s := c.String("opt")
431
-		if s == "fail" {
432
-			return beforeError
433
-		}
434
-
435
-		return nil
436
-	}
437
-
438
-	app.Commands = []cli.Command{
439
-		cli.Command{
440
-			Name: "sub",
441
-			Action: func(c *cli.Context) {
442
-				subcommandRun = true
443
-			},
444
-		},
445
-	}
446
-
447
-	app.Flags = []cli.Flag{
448
-		cli.StringFlag{Name: "opt"},
449
-	}
450
-
451
-	// run with the Before() func succeeding
452
-	err = app.Run([]string{"command", "--opt", "succeed", "sub"})
453
-
454
-	if err != nil {
455
-		t.Fatalf("Run error: %s", err)
456
-	}
457
-
458
-	if beforeRun == false {
459
-		t.Errorf("Before() not executed when expected")
460
-	}
461
-
462
-	if subcommandRun == false {
463
-		t.Errorf("Subcommand not executed when expected")
464
-	}
465
-
466
-	// reset
467
-	beforeRun, subcommandRun = false, false
468
-
469
-	// run with the Before() func failing
470
-	err = app.Run([]string{"command", "--opt", "fail", "sub"})
471
-
472
-	// should be the same error produced by the Before func
473
-	if err != beforeError {
474
-		t.Errorf("Run error expected, but not received")
475
-	}
476
-
477
-	if beforeRun == false {
478
-		t.Errorf("Before() not executed when expected")
479
-	}
480
-
481
-	if subcommandRun == true {
482
-		t.Errorf("Subcommand executed when NOT expected")
483
-	}
484
-
485
-}
486
-
487
-func TestApp_AfterFunc(t *testing.T) {
488
-	afterRun, subcommandRun := false, false
489
-	afterError := fmt.Errorf("fail")
490
-	var err error
491
-
492
-	app := cli.NewApp()
493
-
494
-	app.After = func(c *cli.Context) error {
495
-		afterRun = true
496
-		s := c.String("opt")
497
-		if s == "fail" {
498
-			return afterError
499
-		}
500
-
501
-		return nil
502
-	}
503
-
504
-	app.Commands = []cli.Command{
505
-		cli.Command{
506
-			Name: "sub",
507
-			Action: func(c *cli.Context) {
508
-				subcommandRun = true
509
-			},
510
-		},
511
-	}
512
-
513
-	app.Flags = []cli.Flag{
514
-		cli.StringFlag{Name: "opt"},
515
-	}
516
-
517
-	// run with the After() func succeeding
518
-	err = app.Run([]string{"command", "--opt", "succeed", "sub"})
519
-
520
-	if err != nil {
521
-		t.Fatalf("Run error: %s", err)
522
-	}
523
-
524
-	if afterRun == false {
525
-		t.Errorf("After() not executed when expected")
526
-	}
527
-
528
-	if subcommandRun == false {
529
-		t.Errorf("Subcommand not executed when expected")
530
-	}
531
-
532
-	// reset
533
-	afterRun, subcommandRun = false, false
534
-
535
-	// run with the Before() func failing
536
-	err = app.Run([]string{"command", "--opt", "fail", "sub"})
537
-
538
-	// should be the same error produced by the Before func
539
-	if err != afterError {
540
-		t.Errorf("Run error expected, but not received")
541
-	}
542
-
543
-	if afterRun == false {
544
-		t.Errorf("After() not executed when expected")
545
-	}
546
-
547
-	if subcommandRun == false {
548
-		t.Errorf("Subcommand not executed when expected")
549
-	}
550
-}
551
-
552
-func TestAppNoHelpFlag(t *testing.T) {
553
-	oldFlag := cli.HelpFlag
554
-	defer func() {
555
-		cli.HelpFlag = oldFlag
556
-	}()
557
-
558
-	cli.HelpFlag = cli.BoolFlag{}
559
-
560
-	app := cli.NewApp()
561
-	err := app.Run([]string{"test", "-h"})
562
-
563
-	if err != flag.ErrHelp {
564
-		t.Errorf("expected error about missing help flag, but got: %s (%T)", err, err)
565
-	}
566
-}
567
-
568
-func TestAppHelpPrinter(t *testing.T) {
569
-	oldPrinter := cli.HelpPrinter
570
-	defer func() {
571
-		cli.HelpPrinter = oldPrinter
572
-	}()
573
-
574
-	var wasCalled = false
575
-	cli.HelpPrinter = func(w io.Writer, template string, data interface{}) {
576
-		wasCalled = true
577
-	}
578
-
579
-	app := cli.NewApp()
580
-	app.Run([]string{"-h"})
581
-
582
-	if wasCalled == false {
583
-		t.Errorf("Help printer expected to be called, but was not")
584
-	}
585
-}
586
-
587
-func TestAppVersionPrinter(t *testing.T) {
588
-	oldPrinter := cli.VersionPrinter
589
-	defer func() {
590
-		cli.VersionPrinter = oldPrinter
591
-	}()
592
-
593
-	var wasCalled = false
594
-	cli.VersionPrinter = func(c *cli.Context) {
595
-		wasCalled = true
596
-	}
597
-
598
-	app := cli.NewApp()
599
-	ctx := cli.NewContext(app, nil, nil)
600
-	cli.ShowVersion(ctx)
601
-
602
-	if wasCalled == false {
603
-		t.Errorf("Version printer expected to be called, but was not")
604
-	}
605
-}
606
-
607
-func TestAppCommandNotFound(t *testing.T) {
608
-	beforeRun, subcommandRun := false, false
609
-	app := cli.NewApp()
610
-
611
-	app.CommandNotFound = func(c *cli.Context, command string) {
612
-		beforeRun = true
613
-	}
614
-
615
-	app.Commands = []cli.Command{
616
-		cli.Command{
617
-			Name: "bar",
618
-			Action: func(c *cli.Context) {
619
-				subcommandRun = true
620
-			},
621
-		},
622
-	}
623
-
624
-	app.Run([]string{"command", "foo"})
625
-
626
-	expect(t, beforeRun, true)
627
-	expect(t, subcommandRun, false)
628
-}
629
-
630
-func TestGlobalFlagsInSubcommands(t *testing.T) {
631
-	subcommandRun := false
632
-	parentFlag := false
633
-	app := cli.NewApp()
634
-
635
-	app.Flags = []cli.Flag{
636
-		cli.BoolFlag{Name: "debug, d", Usage: "Enable debugging"},
637
-	}
638
-
639
-	app.Commands = []cli.Command{
640
-		cli.Command{
641
-			Name: "foo",
642
-			Flags: []cli.Flag{
643
-				cli.BoolFlag{Name: "parent, p", Usage: "Parent flag"},
644
-			},
645
-			Subcommands: []cli.Command{
646
-				{
647
-					Name: "bar",
648
-					Action: func(c *cli.Context) {
649
-						if c.GlobalBool("debug") {
650
-							subcommandRun = true
651
-						}
652
-						if c.GlobalBool("parent") {
653
-							parentFlag = true
654
-						}
655
-					},
656
-				},
657
-			},
658
-		},
659
-	}
660
-
661
-	app.Run([]string{"command", "-d", "foo", "-p", "bar"})
662
-
663
-	expect(t, subcommandRun, true)
664
-	expect(t, parentFlag, true)
665
-}
666
-
667
-func TestApp_Run_CommandWithSubcommandHasHelpTopic(t *testing.T) {
668
-	var subcommandHelpTopics = [][]string{
669
-		{"command", "foo", "--help"},
670
-		{"command", "foo", "-h"},
671
-		{"command", "foo", "help"},
672
-	}
673
-
674
-	for _, flagSet := range subcommandHelpTopics {
675
-		t.Logf("==> checking with flags %v", flagSet)
676
-
677
-		app := cli.NewApp()
678
-		buf := new(bytes.Buffer)
679
-		app.Writer = buf
680
-
681
-		subCmdBar := cli.Command{
682
-			Name:  "bar",
683
-			Usage: "does bar things",
684
-		}
685
-		subCmdBaz := cli.Command{
686
-			Name:  "baz",
687
-			Usage: "does baz things",
688
-		}
689
-		cmd := cli.Command{
690
-			Name:        "foo",
691
-			Description: "descriptive wall of text about how it does foo things",
692
-			Subcommands: []cli.Command{subCmdBar, subCmdBaz},
693
-		}
694
-
695
-		app.Commands = []cli.Command{cmd}
696
-		err := app.Run(flagSet)
697
-
698
-		if err != nil {
699
-			t.Error(err)
700
-		}
701
-
702
-		output := buf.String()
703
-		t.Logf("output: %q\n", buf.Bytes())
704
-
705
-		if strings.Contains(output, "No help topic for") {
706
-			t.Errorf("expect a help topic, got none: \n%q", output)
707
-		}
708
-
709
-		for _, shouldContain := range []string{
710
-			cmd.Name, cmd.Description,
711
-			subCmdBar.Name, subCmdBar.Usage,
712
-			subCmdBaz.Name, subCmdBaz.Usage,
713
-		} {
714
-			if !strings.Contains(output, shouldContain) {
715
-				t.Errorf("want help to contain %q, did not: \n%q", shouldContain, output)
716
-			}
717
-		}
718
-	}
719
-}

+ 0
- 13
Godeps/_workspace/src/github.com/codegangsta/cli/autocomplete/bash_autocomplete View File

@@ -1,13 +0,0 @@
1
-#! /bin/bash
2
-
3
-_cli_bash_autocomplete() {
4
-     local cur prev opts base
5
-     COMPREPLY=()
6
-     cur="${COMP_WORDS[COMP_CWORD]}"
7
-     prev="${COMP_WORDS[COMP_CWORD-1]}"
8
-     opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
9
-     COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
10
-     return 0
11
- }
12
-  
13
- complete -F _cli_bash_autocomplete $PROG

+ 0
- 5
Godeps/_workspace/src/github.com/codegangsta/cli/autocomplete/zsh_autocomplete View File

@@ -1,5 +0,0 @@
1
-autoload -U compinit && compinit
2
-autoload -U bashcompinit && bashcompinit
3
-
4
-script_dir=$(dirname $0)
5
-source ${script_dir}/bash_autocomplete

+ 0
- 19
Godeps/_workspace/src/github.com/codegangsta/cli/cli.go View File

@@ -1,19 +0,0 @@
1
-// Package cli provides a minimal framework for creating and organizing command line
2
-// Go applications. cli is designed to be easy to understand and write, the most simple
3
-// cli application can be written as follows:
4
-//   func main() {
5
-//     cli.NewApp().Run(os.Args)
6
-//   }
7
-//
8
-// Of course this application does not do much, so let's make this an actual application:
9
-//   func main() {
10
-//     app := cli.NewApp()
11
-//     app.Name = "greet"
12
-//     app.Usage = "say a greeting"
13
-//     app.Action = func(c *cli.Context) {
14
-//       println("Greetings")
15
-//     }
16
-//
17
-//     app.Run(os.Args)
18
-//   }
19
-package cli

+ 0
- 100
Godeps/_workspace/src/github.com/codegangsta/cli/cli_test.go View File

@@ -1,100 +0,0 @@
1
-package cli_test
2
-
3
-import (
4
-	"os"
5
-
6
-	"github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli"
7
-)
8
-
9
-func Example() {
10
-	app := cli.NewApp()
11
-	app.Name = "todo"
12
-	app.Usage = "task list on the command line"
13
-	app.Commands = []cli.Command{
14
-		{
15
-			Name:    "add",
16
-			Aliases: []string{"a"},
17
-			Usage:   "add a task to the list",
18
-			Action: func(c *cli.Context) {
19
-				println("added task: ", c.Args().First())
20
-			},
21
-		},
22
-		{
23
-			Name:    "complete",
24
-			Aliases: []string{"c"},
25
-			Usage:   "complete a task on the list",
26
-			Action: func(c *cli.Context) {
27
-				println("completed task: ", c.Args().First())
28
-			},
29
-		},
30
-	}
31
-
32
-	app.Run(os.Args)
33
-}
34
-
35
-func ExampleSubcommand() {
36
-	app := cli.NewApp()
37
-	app.Name = "say"
38
-	app.Commands = []cli.Command{
39
-		{
40
-			Name:        "hello",
41
-			Aliases:     []string{"hi"},
42
-			Usage:       "use it to see a description",
43
-			Description: "This is how we describe hello the function",
44
-			Subcommands: []cli.Command{
45
-				{
46
-					Name:        "english",
47
-					Aliases:     []string{"en"},
48
-					Usage:       "sends a greeting in english",
49
-					Description: "greets someone in english",
50
-					Flags: []cli.Flag{
51
-						cli.StringFlag{
52
-							Name:  "name",
53
-							Value: "Bob",
54
-							Usage: "Name of the person to greet",
55
-						},
56
-					},
57
-					Action: func(c *cli.Context) {
58
-						println("Hello, ", c.String("name"))
59
-					},
60
-				}, {
61
-					Name:    "spanish",
62
-					Aliases: []string{"sp"},
63
-					Usage:   "sends a greeting in spanish",
64
-					Flags: []cli.Flag{
65
-						cli.StringFlag{
66
-							Name:  "surname",
67
-							Value: "Jones",
68
-							Usage: "Surname of the person to greet",
69
-						},
70
-					},
71
-					Action: func(c *cli.Context) {
72
-						println("Hola, ", c.String("surname"))
73
-					},
74
-				}, {
75
-					Name:    "french",
76
-					Aliases: []string{"fr"},
77
-					Usage:   "sends a greeting in french",
78
-					Flags: []cli.Flag{
79
-						cli.StringFlag{
80
-							Name:  "nickname",
81
-							Value: "Stevie",
82
-							Usage: "Nickname of the person to greet",
83
-						},
84
-					},
85
-					Action: func(c *cli.Context) {
86
-						println("Bonjour, ", c.String("nickname"))
87
-					},
88
-				},
89
-			},
90
-		}, {
91
-			Name:  "bye",
92
-			Usage: "says goodbye",
93
-			Action: func(c *cli.Context) {
94
-				println("bye")
95
-			},
96
-		},
97
-	}
98
-
99
-	app.Run(os.Args)
100
-}

+ 0
- 184
Godeps/_workspace/src/github.com/codegangsta/cli/command.go View File

@@ -1,184 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"fmt"
5
-	"io/ioutil"
6
-	"strings"
7
-)
8
-
9
-// Command is a subcommand for a cli.App.
10
-type Command struct {
11
-	// The name of the command
12
-	Name string
13
-	// short name of the command. Typically one character (deprecated, use `Aliases`)
14
-	ShortName string
15
-	// A list of aliases for the command
16
-	Aliases []string
17
-	// A short description of the usage of this command
18
-	Usage string
19
-	// A longer explanation of how the command works
20
-	Description string
21
-	// The function to call when checking for bash command completions
22
-	BashComplete func(context *Context)
23
-	// An action to execute before any sub-subcommands are run, but after the context is ready
24
-	// If a non-nil error is returned, no sub-subcommands are run
25
-	Before func(context *Context) error
26
-	// An action to execute after any subcommands are run, but after the subcommand has finished
27
-	// It is run even if Action() panics
28
-	After func(context *Context) error
29
-	// The function to call when this command is invoked
30
-	Action func(context *Context)
31
-	// List of child commands
32
-	Subcommands []Command
33
-	// List of flags to parse
34
-	Flags []Flag
35
-	// Treat all flags as normal arguments if true
36
-	SkipFlagParsing bool
37
-	// Boolean to hide built-in help command
38
-	HideHelp bool
39
-}
40
-
41
-// Invokes the command given the context, parses ctx.Args() to generate command-specific flags
42
-func (c Command) Run(ctx *Context) error {
43
-
44
-	if len(c.Subcommands) > 0 || c.Before != nil || c.After != nil {
45
-		return c.startApp(ctx)
46
-	}
47
-
48
-	if !c.HideHelp && (HelpFlag != BoolFlag{}) {
49
-		// append help to flags
50
-		c.Flags = append(
51
-			c.Flags,
52
-			HelpFlag,
53
-		)
54
-	}
55
-
56
-	if ctx.App.EnableBashCompletion {
57
-		c.Flags = append(c.Flags, BashCompletionFlag)
58
-	}
59
-
60
-	set := flagSet(c.Name, c.Flags)
61
-	set.SetOutput(ioutil.Discard)
62
-
63
-	firstFlagIndex := -1
64
-	terminatorIndex := -1
65
-	for index, arg := range ctx.Args() {
66
-		if arg == "--" {
67
-			terminatorIndex = index
68
-			break
69
-		} else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 {
70
-			firstFlagIndex = index
71
-		}
72
-	}
73
-
74
-	var err error
75
-	if firstFlagIndex > -1 && !c.SkipFlagParsing {
76
-		args := ctx.Args()
77
-		regularArgs := make([]string, len(args[1:firstFlagIndex]))
78
-		copy(regularArgs, args[1:firstFlagIndex])
79
-
80
-		var flagArgs []string
81
-		if terminatorIndex > -1 {
82
-			flagArgs = args[firstFlagIndex:terminatorIndex]
83
-			regularArgs = append(regularArgs, args[terminatorIndex:]...)
84
-		} else {
85
-			flagArgs = args[firstFlagIndex:]
86
-		}
87
-
88
-		err = set.Parse(append(flagArgs, regularArgs...))
89
-	} else {
90
-		err = set.Parse(ctx.Args().Tail())
91
-	}
92
-
93
-	if err != nil {
94
-		fmt.Fprint(ctx.App.Writer, "Incorrect Usage.\n\n")
95
-		ShowCommandHelp(ctx, c.Name)
96
-		fmt.Fprintln(ctx.App.Writer)
97
-		return err
98
-	}
99
-
100
-	nerr := normalizeFlags(c.Flags, set)
101
-	if nerr != nil {
102
-		fmt.Fprintln(ctx.App.Writer, nerr)
103
-		fmt.Fprintln(ctx.App.Writer)
104
-		ShowCommandHelp(ctx, c.Name)
105
-		fmt.Fprintln(ctx.App.Writer)
106
-		return nerr
107
-	}
108
-	context := NewContext(ctx.App, set, ctx)
109
-
110
-	if checkCommandCompletions(context, c.Name) {
111
-		return nil
112
-	}
113
-
114
-	if checkCommandHelp(context, c.Name) {
115
-		return nil
116
-	}
117
-	context.Command = c
118
-	c.Action(context)
119
-	return nil
120
-}
121
-
122
-func (c Command) Names() []string {
123
-	names := []string{c.Name}
124
-
125
-	if c.ShortName != "" {
126
-		names = append(names, c.ShortName)
127
-	}
128
-
129
-	return append(names, c.Aliases...)
130
-}
131
-
132
-// Returns true if Command.Name or Command.ShortName matches given name
133
-func (c Command) HasName(name string) bool {
134
-	for _, n := range c.Names() {
135
-		if n == name {
136
-			return true
137
-		}
138
-	}
139
-	return false
140
-}
141
-
142
-func (c Command) startApp(ctx *Context) error {
143
-	app := NewApp()
144
-
145
-	// set the name and usage
146
-	app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name)
147
-	if c.Description != "" {
148
-		app.Usage = c.Description
149
-	} else {
150
-		app.Usage = c.Usage
151
-	}
152
-
153
-	// set CommandNotFound
154
-	app.CommandNotFound = ctx.App.CommandNotFound
155
-
156
-	// set the flags and commands
157
-	app.Commands = c.Subcommands
158
-	app.Flags = c.Flags
159
-	app.HideHelp = c.HideHelp
160
-
161
-	app.Version = ctx.App.Version
162
-	app.HideVersion = ctx.App.HideVersion
163
-	app.Compiled = ctx.App.Compiled
164
-	app.Author = ctx.App.Author
165
-	app.Email = ctx.App.Email
166
-	app.Writer = ctx.App.Writer
167
-
168
-	// bash completion
169
-	app.EnableBashCompletion = ctx.App.EnableBashCompletion
170
-	if c.BashComplete != nil {
171
-		app.BashComplete = c.BashComplete
172
-	}
173
-
174
-	// set the actions
175
-	app.Before = c.Before
176
-	app.After = c.After
177
-	if c.Action != nil {
178
-		app.Action = c.Action
179
-	} else {
180
-		app.Action = helpSubcommand.Action
181
-	}
182
-
183
-	return app.RunAsSubcommand(ctx)
184
-}

+ 0
- 49
Godeps/_workspace/src/github.com/codegangsta/cli/command_test.go View File

@@ -1,49 +0,0 @@
1
-package cli_test
2
-
3
-import (
4
-	"flag"
5
-	"testing"
6
-
7
-	"github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli"
8
-)
9
-
10
-func TestCommandDoNotIgnoreFlags(t *testing.T) {
11
-	app := cli.NewApp()
12
-	set := flag.NewFlagSet("test", 0)
13
-	test := []string{"blah", "blah", "-break"}
14
-	set.Parse(test)
15
-
16
-	c := cli.NewContext(app, set, nil)
17
-
18
-	command := cli.Command{
19
-		Name:        "test-cmd",
20
-		Aliases:     []string{"tc"},
21
-		Usage:       "this is for testing",
22
-		Description: "testing",
23
-		Action:      func(_ *cli.Context) {},
24
-	}
25
-	err := command.Run(c)
26
-
27
-	expect(t, err.Error(), "flag provided but not defined: -break")
28
-}
29
-
30
-func TestCommandIgnoreFlags(t *testing.T) {
31
-	app := cli.NewApp()
32
-	set := flag.NewFlagSet("test", 0)
33
-	test := []string{"blah", "blah"}
34
-	set.Parse(test)
35
-
36
-	c := cli.NewContext(app, set, nil)
37
-
38
-	command := cli.Command{
39
-		Name:            "test-cmd",
40
-		Aliases:         []string{"tc"},
41
-		Usage:           "this is for testing",
42
-		Description:     "testing",
43
-		Action:          func(_ *cli.Context) {},
44
-		SkipFlagParsing: true,
45
-	}
46
-	err := command.Run(c)
47
-
48
-	expect(t, err, nil)
49
-}

+ 0
- 376
Godeps/_workspace/src/github.com/codegangsta/cli/context.go View File

@@ -1,376 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"errors"
5
-	"flag"
6
-	"strconv"
7
-	"strings"
8
-	"time"
9
-)
10
-
11
-// Context is a type that is passed through to
12
-// each Handler action in a cli application. Context
13
-// can be used to retrieve context-specific Args and
14
-// parsed command-line options.
15
-type Context struct {
16
-	App            *App
17
-	Command        Command
18
-	flagSet        *flag.FlagSet
19
-	setFlags       map[string]bool
20
-	globalSetFlags map[string]bool
21
-	parentContext  *Context
22
-}
23
-
24
-// Creates a new context. For use in when invoking an App or Command action.
25
-func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context {
26
-	return &Context{App: app, flagSet: set, parentContext: parentCtx}
27
-}
28
-
29
-// Looks up the value of a local int flag, returns 0 if no int flag exists
30
-func (c *Context) Int(name string) int {
31
-	return lookupInt(name, c.flagSet)
32
-}
33
-
34
-// Looks up the value of a local time.Duration flag, returns 0 if no time.Duration flag exists
35
-func (c *Context) Duration(name string) time.Duration {
36
-	return lookupDuration(name, c.flagSet)
37
-}
38
-
39
-// Looks up the value of a local float64 flag, returns 0 if no float64 flag exists
40
-func (c *Context) Float64(name string) float64 {
41
-	return lookupFloat64(name, c.flagSet)
42
-}
43
-
44
-// Looks up the value of a local bool flag, returns false if no bool flag exists
45
-func (c *Context) Bool(name string) bool {
46
-	return lookupBool(name, c.flagSet)
47
-}
48
-
49
-// Looks up the value of a local boolT flag, returns false if no bool flag exists
50
-func (c *Context) BoolT(name string) bool {
51
-	return lookupBoolT(name, c.flagSet)
52
-}
53
-
54
-// Looks up the value of a local string flag, returns "" if no string flag exists
55
-func (c *Context) String(name string) string {
56
-	return lookupString(name, c.flagSet)
57
-}
58
-
59
-// Looks up the value of a local string slice flag, returns nil if no string slice flag exists
60
-func (c *Context) StringSlice(name string) []string {
61
-	return lookupStringSlice(name, c.flagSet)
62
-}
63
-
64
-// Looks up the value of a local int slice flag, returns nil if no int slice flag exists
65
-func (c *Context) IntSlice(name string) []int {
66
-	return lookupIntSlice(name, c.flagSet)
67
-}
68
-
69
-// Looks up the value of a local generic flag, returns nil if no generic flag exists
70
-func (c *Context) Generic(name string) interface{} {
71
-	return lookupGeneric(name, c.flagSet)
72
-}
73
-
74
-// Looks up the value of a global int flag, returns 0 if no int flag exists
75
-func (c *Context) GlobalInt(name string) int {
76
-	if fs := lookupParentFlagSet(name, c); fs != nil {
77
-		return lookupInt(name, fs)
78
-	}
79
-	return 0
80
-}
81
-
82
-// Looks up the value of a global time.Duration flag, returns 0 if no time.Duration flag exists
83
-func (c *Context) GlobalDuration(name string) time.Duration {
84
-	if fs := lookupParentFlagSet(name, c); fs != nil {
85
-		return lookupDuration(name, fs)
86
-	}
87
-	return 0
88
-}
89
-
90
-// Looks up the value of a global bool flag, returns false if no bool flag exists
91
-func (c *Context) GlobalBool(name string) bool {
92
-	if fs := lookupParentFlagSet(name, c); fs != nil {
93
-		return lookupBool(name, fs)
94
-	}
95
-	return false
96
-}
97
-
98
-// Looks up the value of a global string flag, returns "" if no string flag exists
99
-func (c *Context) GlobalString(name string) string {
100
-	if fs := lookupParentFlagSet(name, c); fs != nil {
101
-		return lookupString(name, fs)
102
-	}
103
-	return ""
104
-}
105
-
106
-// Looks up the value of a global string slice flag, returns nil if no string slice flag exists
107
-func (c *Context) GlobalStringSlice(name string) []string {
108
-	if fs := lookupParentFlagSet(name, c); fs != nil {
109
-		return lookupStringSlice(name, fs)
110
-	}
111
-	return nil
112
-}
113
-
114
-// Looks up the value of a global int slice flag, returns nil if no int slice flag exists
115
-func (c *Context) GlobalIntSlice(name string) []int {
116
-	if fs := lookupParentFlagSet(name, c); fs != nil {
117
-		return lookupIntSlice(name, fs)
118
-	}
119
-	return nil
120
-}
121
-
122
-// Looks up the value of a global generic flag, returns nil if no generic flag exists
123
-func (c *Context) GlobalGeneric(name string) interface{} {
124
-	if fs := lookupParentFlagSet(name, c); fs != nil {
125
-		return lookupGeneric(name, fs)
126
-	}
127
-	return nil
128
-}
129
-
130
-// Returns the number of flags set
131
-func (c *Context) NumFlags() int {
132
-	return c.flagSet.NFlag()
133
-}
134
-
135
-// Determines if the flag was actually set
136
-func (c *Context) IsSet(name string) bool {
137
-	if c.setFlags == nil {
138
-		c.setFlags = make(map[string]bool)
139
-		c.flagSet.Visit(func(f *flag.Flag) {
140
-			c.setFlags[f.Name] = true
141
-		})
142
-	}
143
-	return c.setFlags[name] == true
144
-}
145
-
146
-// Determines if the global flag was actually set
147
-func (c *Context) GlobalIsSet(name string) bool {
148
-	if c.globalSetFlags == nil {
149
-		c.globalSetFlags = make(map[string]bool)
150
-		for ctx := c.parentContext; ctx != nil && c.globalSetFlags[name] == false; ctx = ctx.parentContext {
151
-			ctx.flagSet.Visit(func(f *flag.Flag) {
152
-				c.globalSetFlags[f.Name] = true
153
-			})
154
-		}
155
-	}
156
-	return c.globalSetFlags[name]
157
-}
158
-
159
-// Returns a slice of flag names used in this context.
160
-func (c *Context) FlagNames() (names []string) {
161
-	for _, flag := range c.Command.Flags {
162
-		name := strings.Split(flag.getName(), ",")[0]
163
-		if name == "help" {
164
-			continue
165
-		}
166
-		names = append(names, name)
167
-	}
168
-	return
169
-}
170
-
171
-// Returns a slice of global flag names used by the app.
172
-func (c *Context) GlobalFlagNames() (names []string) {
173
-	for _, flag := range c.App.Flags {
174
-		name := strings.Split(flag.getName(), ",")[0]
175
-		if name == "help" || name == "version" {
176
-			continue
177
-		}
178
-		names = append(names, name)
179
-	}
180
-	return
181
-}
182
-
183
-type Args []string
184
-
185
-// Returns the command line arguments associated with the context.
186
-func (c *Context) Args() Args {
187
-	args := Args(c.flagSet.Args())
188
-	return args
189
-}
190
-
191
-// Returns the nth argument, or else a blank string
192
-func (a Args) Get(n int) string {
193
-	if len(a) > n {
194
-		return a[n]
195
-	}
196
-	return ""
197
-}
198
-
199
-// Returns the first argument, or else a blank string
200
-func (a Args) First() string {
201
-	return a.Get(0)
202
-}
203
-
204
-// Return the rest of the arguments (not the first one)
205
-// or else an empty string slice
206
-func (a Args) Tail() []string {
207
-	if len(a) >= 2 {
208
-		return []string(a)[1:]
209
-	}
210
-	return []string{}
211
-}
212
-
213
-// Checks if there are any arguments present
214
-func (a Args) Present() bool {
215
-	return len(a) != 0
216
-}
217
-
218
-// Swaps arguments at the given indexes
219
-func (a Args) Swap(from, to int) error {
220
-	if from >= len(a) || to >= len(a) {
221
-		return errors.New("index out of range")
222
-	}
223
-	a[from], a[to] = a[to], a[from]
224
-	return nil
225
-}
226
-
227
-func lookupParentFlagSet(name string, ctx *Context) *flag.FlagSet {
228
-	for ctx := ctx.parentContext; ctx != nil; ctx = ctx.parentContext {
229
-		if f := ctx.flagSet.Lookup(name); f != nil {
230
-			return ctx.flagSet
231
-		}
232
-	}
233
-	return nil
234
-}
235
-
236
-func lookupInt(name string, set *flag.FlagSet) int {
237
-	f := set.Lookup(name)
238
-	if f != nil {
239
-		val, err := strconv.Atoi(f.Value.String())
240
-		if err != nil {
241
-			return 0
242
-		}
243
-		return val
244
-	}
245
-
246
-	return 0
247
-}
248
-
249
-func lookupDuration(name string, set *flag.FlagSet) time.Duration {
250
-	f := set.Lookup(name)
251
-	if f != nil {
252
-		val, err := time.ParseDuration(f.Value.String())
253
-		if err == nil {
254
-			return val
255
-		}
256
-	}
257
-
258
-	return 0
259
-}
260
-
261
-func lookupFloat64(name string, set *flag.FlagSet) float64 {
262
-	f := set.Lookup(name)
263
-	if f != nil {
264
-		val, err := strconv.ParseFloat(f.Value.String(), 64)
265
-		if err != nil {
266
-			return 0
267
-		}
268
-		return val
269
-	}
270
-
271
-	return 0
272
-}
273
-
274
-func lookupString(name string, set *flag.FlagSet) string {
275
-	f := set.Lookup(name)
276
-	if f != nil {
277
-		return f.Value.String()
278
-	}
279
-
280
-	return ""
281
-}
282
-
283
-func lookupStringSlice(name string, set *flag.FlagSet) []string {
284
-	f := set.Lookup(name)
285
-	if f != nil {
286
-		return (f.Value.(*StringSlice)).Value()
287
-
288
-	}
289
-
290
-	return nil
291
-}
292
-
293
-func lookupIntSlice(name string, set *flag.FlagSet) []int {
294
-	f := set.Lookup(name)
295
-	if f != nil {
296
-		return (f.Value.(*IntSlice)).Value()
297
-
298
-	}
299
-
300
-	return nil
301
-}
302
-
303
-func lookupGeneric(name string, set *flag.FlagSet) interface{} {
304
-	f := set.Lookup(name)
305
-	if f != nil {
306
-		return f.Value
307
-	}
308
-	return nil
309
-}
310
-
311
-func lookupBool(name string, set *flag.FlagSet) bool {
312
-	f := set.Lookup(name)
313
-	if f != nil {
314
-		val, err := strconv.ParseBool(f.Value.String())
315
-		if err != nil {
316
-			return false
317
-		}
318
-		return val
319
-	}
320
-
321
-	return false
322
-}
323
-
324
-func lookupBoolT(name string, set *flag.FlagSet) bool {
325
-	f := set.Lookup(name)
326
-	if f != nil {
327
-		val, err := strconv.ParseBool(f.Value.String())
328
-		if err != nil {
329
-			return true
330
-		}
331
-		return val
332
-	}
333
-
334
-	return false
335
-}
336
-
337
-func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) {
338
-	switch ff.Value.(type) {
339
-	case *StringSlice:
340
-	default:
341
-		set.Set(name, ff.Value.String())
342
-	}
343
-}
344
-
345
-func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
346
-	visited := make(map[string]bool)
347
-	set.Visit(func(f *flag.Flag) {
348
-		visited[f.Name] = true
349
-	})
350
-	for _, f := range flags {
351
-		parts := strings.Split(f.getName(), ",")
352
-		if len(parts) == 1 {
353
-			continue
354
-		}
355
-		var ff *flag.Flag
356
-		for _, name := range parts {
357
-			name = strings.Trim(name, " ")
358
-			if visited[name] {
359
-				if ff != nil {
360
-					return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name)
361
-				}
362
-				ff = set.Lookup(name)
363
-			}
364
-		}
365
-		if ff == nil {
366
-			continue
367
-		}
368
-		for _, name := range parts {
369
-			name = strings.Trim(name, " ")
370
-			if !visited[name] {
371
-				copyFlag(name, ff, set)
372
-			}
373
-		}
374
-	}
375
-	return nil
376
-}

+ 0
- 115
Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go View File

@@ -1,115 +0,0 @@
1
-package cli_test
2
-
3
-import (
4
-	"flag"
5
-	"testing"
6
-	"time"
7
-
8
-	"github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli"
9
-)
10
-
11
-func TestNewContext(t *testing.T) {
12
-	set := flag.NewFlagSet("test", 0)
13
-	set.Int("myflag", 12, "doc")
14
-	globalSet := flag.NewFlagSet("test", 0)
15
-	globalSet.Int("myflag", 42, "doc")
16
-	globalCtx := cli.NewContext(nil, globalSet, nil)
17
-	command := cli.Command{Name: "mycommand"}
18
-	c := cli.NewContext(nil, set, globalCtx)
19
-	c.Command = command
20
-	expect(t, c.Int("myflag"), 12)
21
-	expect(t, c.GlobalInt("myflag"), 42)
22
-	expect(t, c.Command.Name, "mycommand")
23
-}
24
-
25
-func TestContext_Int(t *testing.T) {
26
-	set := flag.NewFlagSet("test", 0)
27
-	set.Int("myflag", 12, "doc")
28
-	c := cli.NewContext(nil, set, nil)
29
-	expect(t, c.Int("myflag"), 12)
30
-}
31
-
32
-func TestContext_Duration(t *testing.T) {
33
-	set := flag.NewFlagSet("test", 0)
34
-	set.Duration("myflag", time.Duration(12*time.Second), "doc")
35
-	c := cli.NewContext(nil, set, nil)
36
-	expect(t, c.Duration("myflag"), time.Duration(12*time.Second))
37
-}
38
-
39
-func TestContext_String(t *testing.T) {
40
-	set := flag.NewFlagSet("test", 0)
41
-	set.String("myflag", "hello world", "doc")
42
-	c := cli.NewContext(nil, set, nil)
43
-	expect(t, c.String("myflag"), "hello world")
44
-}
45
-
46
-func TestContext_Bool(t *testing.T) {
47
-	set := flag.NewFlagSet("test", 0)
48
-	set.Bool("myflag", false, "doc")
49
-	c := cli.NewContext(nil, set, nil)
50
-	expect(t, c.Bool("myflag"), false)
51
-}
52
-
53
-func TestContext_BoolT(t *testing.T) {
54
-	set := flag.NewFlagSet("test", 0)
55
-	set.Bool("myflag", true, "doc")
56
-	c := cli.NewContext(nil, set, nil)
57
-	expect(t, c.BoolT("myflag"), true)
58
-}
59
-
60
-func TestContext_Args(t *testing.T) {
61
-	set := flag.NewFlagSet("test", 0)
62
-	set.Bool("myflag", false, "doc")
63
-	c := cli.NewContext(nil, set, nil)
64
-	set.Parse([]string{"--myflag", "bat", "baz"})
65
-	expect(t, len(c.Args()), 2)
66
-	expect(t, c.Bool("myflag"), true)
67
-}
68
-
69
-func TestContext_IsSet(t *testing.T) {
70
-	set := flag.NewFlagSet("test", 0)
71
-	set.Bool("myflag", false, "doc")
72
-	set.String("otherflag", "hello world", "doc")
73
-	globalSet := flag.NewFlagSet("test", 0)
74
-	globalSet.Bool("myflagGlobal", true, "doc")
75
-	globalCtx := cli.NewContext(nil, globalSet, nil)
76
-	c := cli.NewContext(nil, set, globalCtx)
77
-	set.Parse([]string{"--myflag", "bat", "baz"})
78
-	globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
79
-	expect(t, c.IsSet("myflag"), true)
80
-	expect(t, c.IsSet("otherflag"), false)
81
-	expect(t, c.IsSet("bogusflag"), false)
82
-	expect(t, c.IsSet("myflagGlobal"), false)
83
-}
84
-
85
-func TestContext_GlobalIsSet(t *testing.T) {
86
-	set := flag.NewFlagSet("test", 0)
87
-	set.Bool("myflag", false, "doc")
88
-	set.String("otherflag", "hello world", "doc")
89
-	globalSet := flag.NewFlagSet("test", 0)
90
-	globalSet.Bool("myflagGlobal", true, "doc")
91
-	globalSet.Bool("myflagGlobalUnset", true, "doc")
92
-	globalCtx := cli.NewContext(nil, globalSet, nil)
93
-	c := cli.NewContext(nil, set, globalCtx)
94
-	set.Parse([]string{"--myflag", "bat", "baz"})
95
-	globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
96
-	expect(t, c.GlobalIsSet("myflag"), false)
97
-	expect(t, c.GlobalIsSet("otherflag"), false)
98
-	expect(t, c.GlobalIsSet("bogusflag"), false)
99
-	expect(t, c.GlobalIsSet("myflagGlobal"), true)
100
-	expect(t, c.GlobalIsSet("myflagGlobalUnset"), false)
101
-	expect(t, c.GlobalIsSet("bogusGlobal"), false)
102
-}
103
-
104
-func TestContext_NumFlags(t *testing.T) {
105
-	set := flag.NewFlagSet("test", 0)
106
-	set.Bool("myflag", false, "doc")
107
-	set.String("otherflag", "hello world", "doc")
108
-	globalSet := flag.NewFlagSet("test", 0)
109
-	globalSet.Bool("myflagGlobal", true, "doc")
110
-	globalCtx := cli.NewContext(nil, globalSet, nil)
111
-	c := cli.NewContext(nil, set, globalCtx)
112
-	set.Parse([]string{"--myflag", "--otherflag=foo"})
113
-	globalSet.Parse([]string{"--myflagGlobal"})
114
-	expect(t, c.NumFlags(), 2)
115
-}

+ 0
- 460
Godeps/_workspace/src/github.com/codegangsta/cli/flag.go View File

@@ -1,460 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"flag"
5
-	"fmt"
6
-	"os"
7
-	"strconv"
8
-	"strings"
9
-	"time"
10
-)
11
-
12
-// This flag enables bash-completion for all commands and subcommands
13
-var BashCompletionFlag = BoolFlag{
14
-	Name: "generate-bash-completion",
15
-}
16
-
17
-// This flag prints the version for the application
18
-var VersionFlag = BoolFlag{
19
-	Name:  "version, v",
20
-	Usage: "print the version",
21
-}
22
-
23
-// This flag prints the help for all commands and subcommands
24
-// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand
25
-// unless HideHelp is set to true)
26
-var HelpFlag = BoolFlag{
27
-	Name:  "help, h",
28
-	Usage: "show help",
29
-}
30
-
31
-// Flag is a common interface related to parsing flags in cli.
32
-// For more advanced flag parsing techniques, it is recomended that
33
-// this interface be implemented.
34
-type Flag interface {
35
-	fmt.Stringer
36
-	// Apply Flag settings to the given flag set
37
-	Apply(*flag.FlagSet)
38
-	getName() string
39
-}
40
-
41
-func flagSet(name string, flags []Flag) *flag.FlagSet {
42
-	set := flag.NewFlagSet(name, flag.ContinueOnError)
43
-
44
-	for _, f := range flags {
45
-		f.Apply(set)
46
-	}
47
-	return set
48
-}
49
-
50
-func eachName(longName string, fn func(string)) {
51
-	parts := strings.Split(longName, ",")
52
-	for _, name := range parts {
53
-		name = strings.Trim(name, " ")
54
-		fn(name)
55
-	}
56
-}
57
-
58
-// Generic is a generic parseable type identified by a specific flag
59
-type Generic interface {
60
-	Set(value string) error
61
-	String() string
62
-}
63
-
64
-// GenericFlag is the flag type for types implementing Generic
65
-type GenericFlag struct {
66
-	Name   string
67
-	Value  Generic
68
-	Usage  string
69
-	EnvVar string
70
-}
71
-
72
-// String returns the string representation of the generic flag to display the
73
-// help text to the user (uses the String() method of the generic flag to show
74
-// the value)
75
-func (f GenericFlag) String() string {
76
-	return withEnvHint(f.EnvVar, fmt.Sprintf("%s%s \"%v\"\t%v", prefixFor(f.Name), f.Name, f.Value, f.Usage))
77
-}
78
-
79
-// Apply takes the flagset and calls Set on the generic flag with the value
80
-// provided by the user for parsing by the flag
81
-func (f GenericFlag) Apply(set *flag.FlagSet) {
82
-	val := f.Value
83
-	if f.EnvVar != "" {
84
-		for _, envVar := range strings.Split(f.EnvVar, ",") {
85
-			envVar = strings.TrimSpace(envVar)
86
-			if envVal := os.Getenv(envVar); envVal != "" {
87
-				val.Set(envVal)
88
-				break
89
-			}
90
-		}
91
-	}
92
-
93
-	eachName(f.Name, func(name string) {
94
-		set.Var(f.Value, name, f.Usage)
95
-	})
96
-}