New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten printed Windows paths on docker help command #10886

Merged
merged 3 commits into from Feb 19, 2015

Conversation

Projects
None yet
8 participants
@ahmetb
Contributor

ahmetb commented Feb 18, 2015

This makes use of %USERPROFILE% as a substitute for
~ on Windows and prints shorter strings for default
cert paths etc.

Removes string escaping/quotes around default
path values printed in docker help command as they
are not really necessary and adds double backslashes
() on windows to gain some chars and reworded
messages with shorter ones for --tls and -H flags.

Fixes test TestMainHelpWidth on Windows (width
is exactly at 80 char limit).

On Unix it becomes:

Signed-off-by: Ahmet Alp Balkan ahmetalpbalkan@gmail.com
cc: @duglin @SvenDowideit @unclejack @jfrazelle

@@ -26,10 +22,12 @@ func TestMainHelpWidth(t *testing.T) {
lines := strings.Split(out, "\n")
for _, line := range lines {
if len(line) > 80 {
t.Log(out)

This comment has been minimized.

@icecrime

icecrime Feb 18, 2015

Contributor

Is this a testing artifact?

This comment has been minimized.

@ahmetb

ahmetb Feb 18, 2015

Contributor

Oh my bad.

if runtime.GOOS != "windows" {
home = os.Getenv("HOME")
}
home := homedir.Get()
f.VisitAll(func(flag *Flag) {
format := " -%s=%s"
if _, ok := flag.Value.(*stringValue); ok {
// put quotes on the value

This comment has been minimized.

@icecrime

icecrime Feb 18, 2015

Contributor

Comment is outdated.

This comment has been minimized.

@ahmetb

ahmetb Feb 18, 2015

Contributor

Nice catch, this block is not necessary anymore.

@icecrime

This comment has been minimized.

Contributor

icecrime commented Feb 18, 2015

I have a change of behavior that I don't really explain (see the path below).

Without the PR:

$  docker --help | grep ca.pem
  --tlscacert="/home/icecrime/.docker/ca.pem"    Trust only remotes providing a certificate signed by the CA given here

With the PR:

$ docker --help | grep ca.pem
  --tlscacert=~/.docker/ca.pem         Trust certs signed only by this CA
@ahmetb

This comment has been minimized.

Contributor

ahmetb commented Feb 18, 2015

@icecrime umm "Without the PR" is probably the stable build and doesn't contain #10547. That's when ~ is introduced.

@icecrime

This comment has been minimized.

Contributor

icecrime commented Feb 18, 2015

Oh good catch, that explains while I couldn't explain the change from reading the code :-)

}
if home != "" && strings.Contains(line, home) {
t.Fatalf("Line should use ~ instead of %q:\n%s", home, line)
t.Fatalf("Line should use home shortcut instead of %q:\n%s", home, line)

This comment has been minimized.

@icecrime

icecrime Feb 18, 2015

Contributor

Just an idea, but shouldn't we just create the following (either that or a const conditioned by a build tag, whatever):

func homeDirectorySpecifier() string {
    if runtime.GOOS == "windows" {
        return "%USERPROFILE%"
    }
    return "~"
}

That would help us keep the same output as we have today in these error messages (t.Fatalf("Line should use %s instead of...", homeDirectorySpecifier(), ...)), and could be use below for PrintDefaults() implementation.

This comment has been minimized.

@ahmetb

ahmetb Feb 18, 2015

Contributor

@icecrime I actually thought about putting this to pkg/homedir but I'm not sure that's the right place. we use exact same piece of code at pkg/mflag/flag.go below as you can see. suggestions?

This comment has been minimized.

@ahmetb

ahmetb Feb 18, 2015

Contributor

@icecrime oh you already said that. okay should I expose this in pkg/mflag or pkg/homedir?

This comment has been minimized.

@icecrime

icecrime Feb 18, 2015

Contributor

Mmm sorry I have too little overview of pkg/ to provide a relevant opinion here... @tianon maybe? <3

This comment has been minimized.

@duglin

duglin Feb 19, 2015

Contributor

I like the idea of putting all of this home-related code into pkg/homedir

This comment has been minimized.

@ahmetb

ahmetb Feb 19, 2015

Contributor

updated this by putting this functionality into pkg/homedir. please review again.

This comment has been minimized.

@tianon
@SvenDowideit

This comment has been minimized.

Contributor

SvenDowideit commented Feb 19, 2015

nice!

ahmetb added some commits Feb 18, 2015

Shorten help messages for docker cmd flags
In order to fit printed messages to fit 80 chars,
rewording messages for `-H` and `--tls` flags.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
pkg/homedir: implement GetShortcutString()
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
Shorten printed Windows paths on docker help cmd
This makes use of `%USERPROFILE%` as a substitute for
`~` on Windows and prints shorter strings for default
cert paths etc.

Also removes string escaping/quotes around default
path values printed in `docker help` command as they
are not really necessary and adds double backslashes
(\\) on windows.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
@icecrime

This comment has been minimized.

Contributor

icecrime commented Feb 19, 2015

LGTM

@ahmetb

This comment has been minimized.

Contributor

ahmetb commented Feb 19, 2015

@icecrime thanks for reviewing. Jenkins is also happy.

https://jenkins.dockerproject.com/job/Windows-PRs/65/console
=== RUN TestMainHelpWidth
[PASSED]: help - verify main width
--- PASS: TestMainHelpWidth (0.02s) 👍

@jessfraz

This comment has been minimized.

Contributor

jessfraz commented Feb 19, 2015

LGTM

jessfraz pushed a commit that referenced this pull request Feb 19, 2015

Jessie Frazelle
Merge pull request #10886 from ahmetalpbalkan/win-cli/TestMainHelpWid…
…th-fix

Shorten printed Windows paths on docker help command

@jessfraz jessfraz merged commit e3fa8b3 into moby:master Feb 19, 2015

1 of 2 checks passed

windows Jenkins build Windows-PRs 65 has failed
Details
janky Jenkins build Docker-PRs 1352 has succeeded
Details

@ahmetb ahmetb deleted the ahmetb:win-cli/TestMainHelpWidth-fix branch Feb 19, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment