{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/93864533","pull_request_review_id":14398054,"id":93864533,"diff_hunk":"@@ -12,73 +12,88 @@ import (\n \t\"golang.org/x/net/context\"\n )\n \n+type joinTokenOptions struct {\n+\trole   string\n+\trotate bool\n+\tquiet  bool\n+}\n+\n func newJoinTokenCommand(dockerCli *command.DockerCli) *cobra.Command {\n-\tvar rotate, quiet bool\n+\topts := joinTokenOptions{}\n \n \tcmd := &cobra.Command{\n \t\tUse:   \"join-token [OPTIONS] (worker|manager)\",\n \t\tShort: \"Manage join tokens\",\n \t\tArgs:  cli.ExactArgs(1),\n \t\tRunE: func(cmd *cobra.Command, args []string) error {\n-\t\t\tworker := args[0] == \"worker\"\n-\t\t\tmanager := args[0] == \"manager\"\n-\n-\t\t\tif !worker && !manager {\n-\t\t\t\treturn errors.New(\"unknown role \" + args[0])\n-\t\t\t}\n-\n-\t\t\tclient := dockerCli.Client()\n-\t\t\tctx := context.Background()\n-\n-\t\t\tif rotate {\n-\t\t\t\tvar flags swarm.UpdateFlags\n-\n-\t\t\t\tswarm, err := client.SwarmInspect(ctx)\n-\t\t\t\tif err != nil {\n-\t\t\t\t\treturn err\n-\t\t\t\t}\n-\n-\t\t\t\tflags.RotateWorkerToken = worker\n-\t\t\t\tflags.RotateManagerToken = manager\n-\n-\t\t\t\terr = client.SwarmUpdate(ctx, swarm.Version, swarm.Spec, flags)\n-\t\t\t\tif err != nil {\n-\t\t\t\t\treturn err\n-\t\t\t\t}\n-\t\t\t\tif !quiet {\n-\t\t\t\t\tfmt.Fprintf(dockerCli.Out(), \"Successfully rotated %s join token.\\n\\n\", args[0])\n-\t\t\t\t}\n-\t\t\t}\n-\n-\t\t\tswarm, err := client.SwarmInspect(ctx)\n-\t\t\tif err != nil {\n-\t\t\t\treturn err\n-\t\t\t}\n-\n-\t\t\tif quiet {\n-\t\t\t\tif worker {\n-\t\t\t\t\tfmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Worker)\n-\t\t\t\t} else {\n-\t\t\t\t\tfmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Manager)\n-\t\t\t\t}\n-\t\t\t} else {\n-\t\t\t\tinfo, err := client.Info(ctx)\n-\t\t\t\tif err != nil {\n-\t\t\t\t\treturn err\n-\t\t\t\t}\n-\t\t\t\treturn printJoinCommand(ctx, dockerCli, info.Swarm.NodeID, worker, manager)\n-\t\t\t}\n-\t\t\treturn nil\n+\t\t\topts.role = args[0]\n+\t\t\treturn runJoinToken(dockerCli, opts)\n \t\t},\n \t}\n \n \tflags := cmd.Flags()\n-\tflags.BoolVar(&rotate, flagRotate, false, \"Rotate join token\")\n-\tflags.BoolVarP(&quiet, flagQuiet, \"q\", false, \"Only display token\")\n+\tflags.BoolVar(&opts.rotate, flagRotate, false, \"Rotate join token\")\n+\tflags.BoolVarP(&opts.quiet, flagQuiet, \"q\", false, \"Only display token\")\n \n \treturn cmd\n }\n \n+func runJoinToken(dockerCli *command.DockerCli, opts joinTokenOptions) error {\n+\tworker := opts.role == \"worker\"\n+\tmanager := opts.role == \"manager\"\n+\n+\tif !worker && !manager {\n+\t\treturn errors.New(\"unknown role \" + opts.role)\n+\t}\n+\n+\tclient := dockerCli.Client()\n+\tctx := context.Background()\n+\n+\tif opts.rotate {\n+\t\tflags := swarm.UpdateFlags{\n+\t\t\tRotateWorkerToken:  worker,\n+\t\t\tRotateManagerToken: manager,\n+\t\t}\n+\n+\t\tsw, err := client.SwarmInspect(ctx)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tif err := client.SwarmUpdate(ctx, sw.Version, sw.Spec, flags); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tif !opts.quiet {\n+\t\t\tfmt.Fprintf(dockerCli.Out(), \"Successfully rotated %s join token.\\n\\n\", opts.role)\n+\t\t}\n+\t}\n+\n+\t// second SwarmInspect in this function,\n+\t// this is necessary since SwarmUpdate after first changes the join tokens\n+\tsw, err := client.SwarmInspect(ctx)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tif opts.quiet && worker {\n+\t\tfmt.Fprintln(dockerCli.Out(), sw.JoinTokens.Worker)\n+\t\treturn nil\n+\t}\n+\n+\tif opts.quiet && manager {\n+\t\tfmt.Fprintln(dockerCli.Out(), sw.JoinTokens.Manager)\n+\t\treturn nil\n+\t}\n+\n+\tinfo, err := client.Info(ctx)\n+\tif err != nil {\n+\t\treturn err\n+\t}","path":"cli/command/swarm/join_token.go","position":null,"original_position":133,"commit_id":"0b243acbfccddc150d4bb8321d41713a67e039fc","original_commit_id":"226d113fcd8548542a5efce4a04b327c4443182d","user":{"login":"allencloud","id":9465626,"avatar_url":"https://avatars.githubusercontent.com/u/9465626?v=3","gravatar_id":"","url":"https://api.github.com/users/allencloud","html_url":"https://github.com/allencloud","followers_url":"https://api.github.com/users/allencloud/followers","following_url":"https://api.github.com/users/allencloud/following{/other_user}","gists_url":"https://api.github.com/users/allencloud/gists{/gist_id}","starred_url":"https://api.github.com/users/allencloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allencloud/subscriptions","organizations_url":"https://api.github.com/users/allencloud/orgs","repos_url":"https://api.github.com/users/allencloud/repos","events_url":"https://api.github.com/users/allencloud/events{/privacy}","received_events_url":"https://api.github.com/users/allencloud/received_events","type":"User","site_admin":false},"body":"PTAL @thaJeztah ","created_at":"2016-12-26T12:34:46Z","updated_at":"2016-12-26T12:34:46Z","html_url":"https://github.com/docker/docker/pull/28692#discussion_r93864533","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/28692","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/93864533"},"html":{"href":"https://github.com/docker/docker/pull/28692#discussion_r93864533"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/28692"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/28692","id":94742141,"html_url":"https://github.com/docker/docker/pull/28692","diff_url":"https://github.com/docker/docker/pull/28692.diff","patch_url":"https://github.com/docker/docker/pull/28692.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/28692","number":28692,"state":"open","locked":false,"title":"refactor code to split function out of command definition scope","user":{"login":"allencloud","id":9465626,"avatar_url":"https://avatars.githubusercontent.com/u/9465626?v=3","gravatar_id":"","url":"https://api.github.com/users/allencloud","html_url":"https://github.com/allencloud","followers_url":"https://api.github.com/users/allencloud/followers","following_url":"https://api.github.com/users/allencloud/following{/other_user}","gists_url":"https://api.github.com/users/allencloud/gists{/gist_id}","starred_url":"https://api.github.com/users/allencloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allencloud/subscriptions","organizations_url":"https://api.github.com/users/allencloud/orgs","repos_url":"https://api.github.com/users/allencloud/repos","events_url":"https://api.github.com/users/allencloud/events{/privacy}","received_events_url":"https://api.github.com/users/allencloud/received_events","type":"User","site_admin":false},"body":"I found that in client side of swarm part, some action implementation are in command definition.\r\n\r\nI think it is better and more readable to split them out of the definition scope. It is some kind of code structure refactor thing.\r\n\r\n**- What I did**\r\n\r\n**- How I did it**\r\n\r\n**- How to verify it**\r\n\r\n**- Description for the changelog**\r\n<!--\r\nWrite a short (one line) summary that describes the changes in this\r\npull request for inclusion in the changelog:\r\n-->\r\n\r\n\r\n**- A picture of a cute animal (not mandatory but encouraged)**\r\n\r\n\r\nSigned-off-by: allencloud <allen.sun@daocloud.io>","created_at":"2016-11-22T03:30:24Z","updated_at":"2016-12-26T12:34:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"195d1fb59a598b4a8e79b0f13154f03a25cc4687","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/docker/docker/milestones/60","html_url":"https://github.com/docker/docker/milestone/60","labels_url":"https://api.github.com/repos/docker/docker/milestones/60/labels","id":2126145,"number":60,"title":"1.14.0","description":null,"creator":{"login":"vieux","id":1032519,"avatar_url":"https://avatars.githubusercontent.com/u/1032519?v=3","gravatar_id":"","url":"https://api.github.com/users/vieux","html_url":"https://github.com/vieux","followers_url":"https://api.github.com/users/vieux/followers","following_url":"https://api.github.com/users/vieux/following{/other_user}","gists_url":"https://api.github.com/users/vieux/gists{/gist_id}","starred_url":"https://api.github.com/users/vieux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vieux/subscriptions","organizations_url":"https://api.github.com/users/vieux/orgs","repos_url":"https://api.github.com/users/vieux/repos","events_url":"https://api.github.com/users/vieux/events{/privacy}","received_events_url":"https://api.github.com/users/vieux/received_events","type":"User","site_admin":false},"open_issues":21,"closed_issues":153,"state":"open","created_at":"2016-11-10T02:23:44Z","updated_at":"2016-12-26T05:56:57Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/docker/docker/pulls/28692/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/28692/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/28692/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/0b243acbfccddc150d4bb8321d41713a67e039fc","head":{"label":"allencloud:splict-function-out-of-command-denifition-scope","ref":"splict-function-out-of-command-denifition-scope","sha":"0b243acbfccddc150d4bb8321d41713a67e039fc","user":{"login":"allencloud","id":9465626,"avatar_url":"https://avatars.githubusercontent.com/u/9465626?v=3","gravatar_id":"","url":"https://api.github.com/users/allencloud","html_url":"https://github.com/allencloud","followers_url":"https://api.github.com/users/allencloud/followers","following_url":"https://api.github.com/users/allencloud/following{/other_user}","gists_url":"https://api.github.com/users/allencloud/gists{/gist_id}","starred_url":"https://api.github.com/users/allencloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allencloud/subscriptions","organizations_url":"https://api.github.com/users/allencloud/orgs","repos_url":"https://api.github.com/users/allencloud/repos","events_url":"https://api.github.com/users/allencloud/events{/privacy}","received_events_url":"https://api.github.com/users/allencloud/received_events","type":"User","site_admin":false},"repo":{"id":52540894,"name":"docker","full_name":"allencloud/docker","owner":{"login":"allencloud","id":9465626,"avatar_url":"https://avatars.githubusercontent.com/u/9465626?v=3","gravatar_id":"","url":"https://api.github.com/users/allencloud","html_url":"https://github.com/allencloud","followers_url":"https://api.github.com/users/allencloud/followers","following_url":"https://api.github.com/users/allencloud/following{/other_user}","gists_url":"https://api.github.com/users/allencloud/gists{/gist_id}","starred_url":"https://api.github.com/users/allencloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allencloud/subscriptions","organizations_url":"https://api.github.com/users/allencloud/orgs","repos_url":"https://api.github.com/users/allencloud/repos","events_url":"https://api.github.com/users/allencloud/events{/privacy}","received_events_url":"https://api.github.com/users/allencloud/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/allencloud/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/allencloud/docker","forks_url":"https://api.github.com/repos/allencloud/docker/forks","keys_url":"https://api.github.com/repos/allencloud/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allencloud/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allencloud/docker/teams","hooks_url":"https://api.github.com/repos/allencloud/docker/hooks","issue_events_url":"https://api.github.com/repos/allencloud/docker/issues/events{/number}","events_url":"https://api.github.com/repos/allencloud/docker/events","assignees_url":"https://api.github.com/repos/allencloud/docker/assignees{/user}","branches_url":"https://api.github.com/repos/allencloud/docker/branches{/branch}","tags_url":"https://api.github.com/repos/allencloud/docker/tags","blobs_url":"https://api.github.com/repos/allencloud/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allencloud/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allencloud/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/allencloud/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allencloud/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/allencloud/docker/languages","stargazers_url":"https://api.github.com/repos/allencloud/docker/stargazers","contributors_url":"https://api.github.com/repos/allencloud/docker/contributors","subscribers_url":"https://api.github.com/repos/allencloud/docker/subscribers","subscription_url":"https://api.github.com/repos/allencloud/docker/subscription","commits_url":"https://api.github.com/repos/allencloud/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/allencloud/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/allencloud/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/allencloud/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/allencloud/docker/contents/{+path}","compare_url":"https://api.github.com/repos/allencloud/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allencloud/docker/merges","archive_url":"https://api.github.com/repos/allencloud/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allencloud/docker/downloads","issues_url":"https://api.github.com/repos/allencloud/docker/issues{/number}","pulls_url":"https://api.github.com/repos/allencloud/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/allencloud/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/allencloud/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allencloud/docker/labels{/name}","releases_url":"https://api.github.com/repos/allencloud/docker/releases{/id}","deployments_url":"https://api.github.com/repos/allencloud/docker/deployments","created_at":"2016-02-25T16:46:58Z","updated_at":"2016-12-17T08:41:43Z","pushed_at":"2016-12-26T12:12:50Z","git_url":"git://github.com/allencloud/docker.git","ssh_url":"git@github.com:allencloud/docker.git","clone_url":"https://github.com/allencloud/docker.git","svn_url":"https://github.com/allencloud/docker","homepage":"http://www.docker.com","size":117638,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"fb03b56b9b81182ef8561c57e2e7626658dc943b","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","deployments_url":"https://api.github.com/repos/docker/docker/deployments","created_at":"2013-01-18T18:10:57Z","updated_at":"2016-12-26T11:37:04Z","pushed_at":"2016-12-26T12:14:00Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":119065,"stargazers_count":38133,"watchers_count":38133,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11377,"mirror_url":null,"open_issues_count":2063,"forks":11377,"open_issues":2063,"watchers":38133,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/28692"},"html":{"href":"https://github.com/docker/docker/pull/28692"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/28692"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/28692/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/28692/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/28692/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/0b243acbfccddc150d4bb8321d41713a67e039fc"}}}}
{"actor":{"display_login":"allencloud"}}