{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/etcd-starter/pulls/comments/26992020","id":26992020,"diff_hunk":"@@ -24,17 +24,68 @@\n package main\n \n import (\n+\t\"flag\"\n+\t\"fmt\"\n \t\"os\"\n+\t\"regexp\"\n \n \t\"github.com/coreos/etcd-starter/starter\"\n )\n \n const defaultInternalBinaryDir = \"/usr/libexec/etcd/internal_versions/\"\n \n+const usage = `usage: etcd-starter [flags]\n+start v0.4 or v2.0 etcd server based on the layout of data directory and the content inside wal and snapshot\n+\n+etcd-starter --version\n+show the version of etcd-starter and exit.\n+\n+etcd-starter -h | --help\n+show the help information about etcd\n+\n+etcd-starter [etcd flags]\n+start v0.4 or v2.0 etcd using the given flags\n+\n+Please check etcd documents for more information about etcd flag usage.\n+`\n+\n+var (\n+\tshowVersion bool\n+)\n+\n func main() {\n+\tfs := flag.NewFlagSet(\"etcd-starter\", flag.ContinueOnError)\n+\tfs.BoolVar(&showVersion, \"version\", false, \"print version and exit\")\n+\tfs.Usage = func() {\n+\t\tfmt.Println(usage)\n+\t\tos.Exit(0)\n+\t}\n+\n+\tmainArgs, etcdArgs := filterArgs()\n+\tfs.Parse(mainArgs)\n+\n+\tif showVersion {\n+\t\tfmt.Println(\"etcd-starter version\", version)\n+\t\tos.Exit(0)\n+\t}\n+\n \tdir := os.Getenv(\"ETCD_INTERNAL_BINARY_DIR\")\n \tif dir == \"\" {\n \t\tdir = defaultInternalBinaryDir\n \t}\n-\tstarter.StartDesiredVersion(dir, os.Args[1:])\n+\tstarter.StartDesiredVersion(dir, etcdArgs)\n+}\n+\n+func filterArgs() ([]string, []string) {\n+\tmainArgs := make([]string, 0)\n+\tetcdArgs := make([]string, 0)\n+\tpattern := regexp.MustCompile(\"--version|-version|-h|--help|-help\")\n+\tfor _, arg := range os.Args[1:] {\n+\t\tif pattern.MatchString(arg) {\n+\t\t\tmainArgs = append(mainArgs, arg)\n+\t\t\tcontinue","path":"main.go","position":64,"original_position":64,"commit_id":"31e819ba24542b86e47c80a9b58f4cfb93a0f891","original_commit_id":"31e819ba24542b86e47c80a9b58f4cfb93a0f891","user":{"login":"crawford","id":368848,"avatar_url":"https://avatars.githubusercontent.com/u/368848?v=3","gravatar_id":"","url":"https://api.github.com/users/crawford","html_url":"https://github.com/crawford","followers_url":"https://api.github.com/users/crawford/followers","following_url":"https://api.github.com/users/crawford/following{/other_user}","gists_url":"https://api.github.com/users/crawford/gists{/gist_id}","starred_url":"https://api.github.com/users/crawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crawford/subscriptions","organizations_url":"https://api.github.com/users/crawford/orgs","repos_url":"https://api.github.com/users/crawford/repos","events_url":"https://api.github.com/users/crawford/events{/privacy}","received_events_url":"https://api.github.com/users/crawford/received_events","type":"User","site_admin":false},"body":"Can you just use an \"if else\" here?","created_at":"2015-03-23T23:41:22Z","updated_at":"2015-03-23T23:41:22Z","html_url":"https://github.com/coreos/etcd-starter/pull/12#discussion_r26992020","pull_request_url":"https://api.github.com/repos/coreos/etcd-starter/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd-starter/pulls/comments/26992020"},"html":{"href":"https://github.com/coreos/etcd-starter/pull/12#discussion_r26992020"},"pull_request":{"href":"https://api.github.com/repos/coreos/etcd-starter/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/etcd-starter/pulls/12","id":31782935,"html_url":"https://github.com/coreos/etcd-starter/pull/12","diff_url":"https://github.com/coreos/etcd-starter/pull/12.diff","patch_url":"https://github.com/coreos/etcd-starter/pull/12.patch","issue_url":"https://api.github.com/repos/coreos/etcd-starter/issues/12","number":12,"state":"open","locked":false,"title":"etcd-starter: add version flag","user":{"login":"kelseyhightower","id":1123322,"avatar_url":"https://avatars.githubusercontent.com/u/1123322?v=3","gravatar_id":"","url":"https://api.github.com/users/kelseyhightower","html_url":"https://github.com/kelseyhightower","followers_url":"https://api.github.com/users/kelseyhightower/followers","following_url":"https://api.github.com/users/kelseyhightower/following{/other_user}","gists_url":"https://api.github.com/users/kelseyhightower/gists{/gist_id}","starred_url":"https://api.github.com/users/kelseyhightower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kelseyhightower/subscriptions","organizations_url":"https://api.github.com/users/kelseyhightower/orgs","repos_url":"https://api.github.com/users/kelseyhightower/repos","events_url":"https://api.github.com/users/kelseyhightower/events{/privacy}","received_events_url":"https://api.github.com/users/kelseyhightower/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-23T23:02:41Z","updated_at":"2015-03-23T23:41:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5bab31af7a002c401511b88265d1ba331ab99f0b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coreos/etcd-starter/pulls/12/commits","review_comments_url":"https://api.github.com/repos/coreos/etcd-starter/pulls/12/comments","review_comment_url":"https://api.github.com/repos/coreos/etcd-starter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/etcd-starter/issues/12/comments","statuses_url":"https://api.github.com/repos/coreos/etcd-starter/statuses/31e819ba24542b86e47c80a9b58f4cfb93a0f891","head":{"label":"kelseyhightower:add-version-flag","ref":"add-version-flag","sha":"31e819ba24542b86e47c80a9b58f4cfb93a0f891","user":{"login":"kelseyhightower","id":1123322,"avatar_url":"https://avatars.githubusercontent.com/u/1123322?v=3","gravatar_id":"","url":"https://api.github.com/users/kelseyhightower","html_url":"https://github.com/kelseyhightower","followers_url":"https://api.github.com/users/kelseyhightower/followers","following_url":"https://api.github.com/users/kelseyhightower/following{/other_user}","gists_url":"https://api.github.com/users/kelseyhightower/gists{/gist_id}","starred_url":"https://api.github.com/users/kelseyhightower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kelseyhightower/subscriptions","organizations_url":"https://api.github.com/users/kelseyhightower/orgs","repos_url":"https://api.github.com/users/kelseyhightower/repos","events_url":"https://api.github.com/users/kelseyhightower/events{/privacy}","received_events_url":"https://api.github.com/users/kelseyhightower/received_events","type":"User","site_admin":false},"repo":{"id":32603279,"name":"etcd-starter","full_name":"kelseyhightower/etcd-starter","owner":{"login":"kelseyhightower","id":1123322,"avatar_url":"https://avatars.githubusercontent.com/u/1123322?v=3","gravatar_id":"","url":"https://api.github.com/users/kelseyhightower","html_url":"https://github.com/kelseyhightower","followers_url":"https://api.github.com/users/kelseyhightower/followers","following_url":"https://api.github.com/users/kelseyhightower/following{/other_user}","gists_url":"https://api.github.com/users/kelseyhightower/gists{/gist_id}","starred_url":"https://api.github.com/users/kelseyhightower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kelseyhightower/subscriptions","organizations_url":"https://api.github.com/users/kelseyhightower/orgs","repos_url":"https://api.github.com/users/kelseyhightower/repos","events_url":"https://api.github.com/users/kelseyhightower/events{/privacy}","received_events_url":"https://api.github.com/users/kelseyhightower/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kelseyhightower/etcd-starter","description":"starter code to do binary switch and flag trick","fork":true,"url":"https://api.github.com/repos/kelseyhightower/etcd-starter","forks_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/forks","keys_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/teams","hooks_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/hooks","issue_events_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/issues/events{/number}","events_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/events","assignees_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/assignees{/user}","branches_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/branches{/branch}","tags_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/tags","blobs_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/git/refs{/sha}","trees_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/statuses/{sha}","languages_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/languages","stargazers_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/stargazers","contributors_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/contributors","subscribers_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/subscribers","subscription_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/subscription","commits_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/commits{/sha}","git_commits_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/git/commits{/sha}","comments_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/comments{/number}","issue_comment_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/issues/comments{/number}","contents_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/contents/{+path}","compare_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/merges","archive_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/downloads","issues_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/issues{/number}","pulls_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/pulls{/number}","milestones_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/milestones{/number}","notifications_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/labels{/name}","releases_url":"https://api.github.com/repos/kelseyhightower/etcd-starter/releases{/id}","created_at":"2015-03-20T19:38:57Z","updated_at":"2015-03-21T15:40:31Z","pushed_at":"2015-03-23T23:38:31Z","git_url":"git://github.com/kelseyhightower/etcd-starter.git","ssh_url":"git@github.com:kelseyhightower/etcd-starter.git","clone_url":"https://github.com/kelseyhightower/etcd-starter.git","svn_url":"https://github.com/kelseyhightower/etcd-starter","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"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":0,"default_branch":"master"}},"base":{"label":"coreos:master","ref":"master","sha":"4b8b1e89d90665257817f284f48be217cf6328a4","user":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":32548704,"name":"etcd-starter","full_name":"coreos/etcd-starter","owner":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coreos/etcd-starter","description":"starter code to do binary switch and flag trick","fork":false,"url":"https://api.github.com/repos/coreos/etcd-starter","forks_url":"https://api.github.com/repos/coreos/etcd-starter/forks","keys_url":"https://api.github.com/repos/coreos/etcd-starter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/etcd-starter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/etcd-starter/teams","hooks_url":"https://api.github.com/repos/coreos/etcd-starter/hooks","issue_events_url":"https://api.github.com/repos/coreos/etcd-starter/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/etcd-starter/events","assignees_url":"https://api.github.com/repos/coreos/etcd-starter/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/etcd-starter/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/etcd-starter/tags","blobs_url":"https://api.github.com/repos/coreos/etcd-starter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/etcd-starter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/etcd-starter/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/etcd-starter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/etcd-starter/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/etcd-starter/languages","stargazers_url":"https://api.github.com/repos/coreos/etcd-starter/stargazers","contributors_url":"https://api.github.com/repos/coreos/etcd-starter/contributors","subscribers_url":"https://api.github.com/repos/coreos/etcd-starter/subscribers","subscription_url":"https://api.github.com/repos/coreos/etcd-starter/subscription","commits_url":"https://api.github.com/repos/coreos/etcd-starter/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/etcd-starter/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/etcd-starter/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/etcd-starter/issues/comments{/number}","contents_url":"https://api.github.com/repos/coreos/etcd-starter/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/etcd-starter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/etcd-starter/merges","archive_url":"https://api.github.com/repos/coreos/etcd-starter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/etcd-starter/downloads","issues_url":"https://api.github.com/repos/coreos/etcd-starter/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/etcd-starter/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/etcd-starter/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/etcd-starter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/etcd-starter/labels{/name}","releases_url":"https://api.github.com/repos/coreos/etcd-starter/releases{/id}","created_at":"2015-03-19T22:06:26Z","updated_at":"2015-03-23T22:48:10Z","pushed_at":"2015-03-23T23:38:32Z","git_url":"git://github.com/coreos/etcd-starter.git","ssh_url":"git@github.com:coreos/etcd-starter.git","clone_url":"https://github.com/coreos/etcd-starter.git","svn_url":"https://github.com/coreos/etcd-starter","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":3,"forks":3,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/etcd-starter/pulls/12"},"html":{"href":"https://github.com/coreos/etcd-starter/pull/12"},"issue":{"href":"https://api.github.com/repos/coreos/etcd-starter/issues/12"},"comments":{"href":"https://api.github.com/repos/coreos/etcd-starter/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/etcd-starter/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/etcd-starter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/etcd-starter/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/etcd-starter/statuses/31e819ba24542b86e47c80a9b58f4cfb93a0f891"}}}}