heroku/hk — pull request #129 by bgentry (2014-03-24 12:32:49+00:00)
Title: Use pflag for long opts + disable duplicate flags

Switch out the flag package from the stdlib to pflag, which offers POSIX/GNU-style -- flags, and support for interspersed flags and non-flag arguments (i.e. `arg1 -f val arg2`).

Use the [bgentry fork of the pflag package](https://github.com/bgentry/pflag) so long flags can have values separated with a space as well as equals, and so duplicate flags can be disabled.

None of the help text has been updated to show long form flags yet. I'd like to test this out to see if the behavior is acceptable before going through that effort.

Here are some examples of input that is now acceptable:

```
➜ ~ hk create --region eu myapp
Created myapp.

➜ ~ hk set OMG=wtf -a myapp
Set env vars and restarted myapp.

➜ ~ hk set OMG=wtf --app myapp
Set env vars and restarted myapp.

➜ ~ hk unset OMG -a myapp
Unset env vars and restarted myapp.

➜ ~ hk run echo hello -a myapp
Running `echo hello` on myapp as run.1300:
hello
```

Notably, this change has the side effect of allowing the somewhat magical behavior of flags being pulled out of the middle of commands with `run`. For example, this fails:

```
➜ ~ hk run ls -a bin
error: You do not have access to the app bin.
```

Whereas either of the following forms would work (assuming I'm in a dir with a heroku git remote):

```
➜ ~ hk run -- ls -a bin
Running `ls -a bin` on myapp as run.2034:
. .. web worker

➜ ~ hk run "ls -a bin"
Running `ls -a bin` on myapp as run.9070:
. .. web worker
```

Also, attempting to run a command that has options will blow up if those options are unknown:

```
➜ ~ hk run ruby -v -a hkdist
unknown shorthand flag: 'v' in -v
Usage: hk run [-s ] [-d] [...]
...
error: unknown shorthand flag: 'v' in -v
```

That can of course be worked around using a `--` or quoted command:

```
➜ ~ hk run -a hkdist -- ruby -v
```

I'm now ok with this behavior as it's the least awful design I could come up with. Other commands (besides `run`) are able to keep the flexibility of interspersed flags and non-flag args, which has been a frequent pain point for users of hk thus far.

I'd still like to improve the help output for `run` to provide some examples of the `--` or quoted forms.

Is anything else missing?

/cc @max @kr