Skip to content

Use spf13/cobra for docker commit#23309

Merged
LK4D4 merged 1 commit intomoby:masterfrom
yongtang:23211-spf13-cobra-commit
Jun 13, 2016
Merged

Use spf13/cobra for docker commit#23309
LK4D4 merged 1 commit intomoby:masterfrom
yongtang:23211-spf13-cobra-commit

Conversation

@yongtang
Copy link
Copy Markdown
Member

@yongtang yongtang commented Jun 6, 2016

This fix is part of the effort to convert commands to spf13/cobra #23211.

Thif fix coverted command docker commit to use spf13/cobra

Signed-off-by: Yong Tang [email protected]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double quotes is really weird. is it like things escaped in cobra or what?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @LK4D4 for the review. It looks like cobra requires quotes from outside (as there is a space in CMD and []. But then to escape the quotes inside the quotes, a double quotes will be needed.

Therefore the whole argument has to be (single quotes outside and double quotes inside):

"CMD [""/bin/sh""]"

Otherwise it will return error:

invalid argument "CMD [\"/bin/sh\"]" for --change: line 1, column 5: bare " in non-quoted-field

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @dnephin
In a shell (zsh), with docker 1.11 : λ docker commit --change 'CMD ["/bin/sh"]' 830 works fine, with current master docker commit --change 'CMD ["/bin/sh"]' ef9 returns "invalid argument "CMD ["/bin/sh"]" for --change: line 1, column 5: bare " in non-quoted-field".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe related to https://github.com/dnephin/cobra/blob/fork/command.go#L358-L396 ?

I think the error is coming from https://golang.org/pkg/encoding/csv/, which I think is called from opts.ListOpts. I think pflags must have been doing something funky to make this work? Maybe the "add single quotes" patch that we didn't add.

What if you use a StringSliceVar() here instead of ListOps ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnephin At the moment --change use StringSliceVarP. I searched the web and most of the same error message bare " in non-quoted-field" points to golang's csv package. I don't know enough detail about the implementation in cobra though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry I got that backwards. It used to be a ListOpts, so I think that
is the difference. Does it work if you go back to using the list opts, or
is it broken with both types ?
On Jun 8, 2016 11:38 AM, "Yong Tang" [email protected] wrote:

In integration-cli/docker_cli_commit_test.go
#23309 (comment):

@@ -116,9 +116,9 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
"--change", "ENV test 1",
"--change", "ENV PATH /foo",
"--change", "LABEL foo bar",

  •   "--change", "CMD [\"/bin/sh\"]",
    
  •   "--change", `"CMD [""/bin/sh""]"`,
    

@dnephin https://github.com/dnephin At the moment --change use
StringSliceVarP. I searched the web and most of the same error message bare
" in non-quoted-field" points to golang's csv package. I don't know
enough detail about the implementation in cobra though.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/docker/docker/pull/23309/files/89edc4e36c371d04c5d65ff1d330f13d5d4fdc52#r66279789,
or mute the thread
https://github.com/notifications/unsubscribe/AAa_REm_dIKPUKsYjV_aM_a-4Cnk7IvEks5qJuHogaJpZM4Iu_PI
.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, StringSliceVar is the one that uses csv, and ListOpts does not. So changing the type back to the old type should fix this issue and you'll be able to revert this change to the test.

Copy link
Copy Markdown
Member Author

@yongtang yongtang Jun 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnephin I tried with ListOpts and it woks as expected. Thanks for the help!

@yongtang yongtang force-pushed the 23211-spf13-cobra-commit branch from 89edc4e to 7bff3ae Compare June 7, 2016 02:11
Comment thread api/client/container/commit.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequiresRangeArgs(1, 2) ?

I guess this is already in master

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dnephin. RequiresMinMaxArgs() was added as part of the #23286. Now I have changed the name to RequiresRangeArgs() and updated the pull request.

@yongtang yongtang force-pushed the 23211-spf13-cobra-commit branch 2 times, most recently from b6a77cc to 4170414 Compare June 7, 2016 15:22
@thaJeztah
Copy link
Copy Markdown
Member

needs a rebase as well now

@yongtang yongtang force-pushed the 23211-spf13-cobra-commit branch from 4170414 to e8ba0a1 Compare June 8, 2016 02:07
@yongtang
Copy link
Copy Markdown
Member Author

yongtang commented Jun 8, 2016

Thanks @thaJeztah the PR has been rebased.

This fix is part of the effort to convert commands to spf13/cobra moby#23211.

Thif fix coverted command `docker commit` to use spf13/cobra

NOTE: `RequiresMinMaxArgs()` has been renamed to `RequiresRangeArgs()`.

Signed-off-by: Yong Tang <[email protected]>
@yongtang yongtang force-pushed the 23211-spf13-cobra-commit branch from e8ba0a1 to 939a142 Compare June 9, 2016 02:26
@yongtang
Copy link
Copy Markdown
Member Author

yongtang commented Jun 9, 2016

Thanks @dnephin for the help. The pull request has been updated. Please let me know if there are any issues.

@dnephin
Copy link
Copy Markdown
Member

dnephin commented Jun 9, 2016

LGTM

@icecrime icecrime modified the milestone: 1.12.0 Jun 13, 2016
@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Jun 13, 2016

LGTM

@LK4D4 LK4D4 merged commit e6c49bf into moby:master Jun 13, 2016
@thaJeztah thaJeztah added this to the 1.12.0 milestone Jun 13, 2016
@yongtang yongtang deleted the 23211-spf13-cobra-commit branch June 14, 2016 02:07
@dnephin dnephin mentioned this pull request Jul 18, 2016
43 tasks
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants