{"id":2445,"date":"2016-09-29T07:16:34","date_gmt":"2016-09-29T07:16:34","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=2445"},"modified":"2017-01-27T09:42:08","modified_gmt":"2017-01-27T00:42:08","slug":"golang-%eb%aa%85%eb%a0%b9%ec%a4%84%ec%97%90-%eb%8c%80%ed%95%9c-%ed%94%8c%eb%9e%98%ea%b7%b8-%ec%96%bb%ea%b8%b0command-line-flag","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=2445","title":{"rendered":"[Golang] \uba85\ub839\uc904\uc5d0 \ub300\ud55c \ud50c\ub798\uadf8 \uc5bb\uae30(Command-Line Flag)"},"content":{"rendered":"<p>Go\uc5d0\uc11c \ub9cc\ub4e4\uc5b4\uc9c4 \uc2e4\ud589 \ud30c\uc77c\uc744 \uc2e4\ud589\ud560 \ub54c, \uba85\ub839\uc904\uc5d0 \uc785\ub825\ud55c \ud50c\ub798\uadf8 \uac12\uc744 \uc27d\uac8c \uc5bb\uae30 \uc704\ud574 \uc81c\uacf5\ud558\ub294 flag \ud328\ud0a4\uc9c0 \uc0ac\uc6a9\uc5d0 \ub300\ud55c \ucf54\ub4dc\ub97c \uc815\ub9ac\ud574 \ubd05\ub2c8\ub2e4. \uc544\ub798\uc758 \ucf54\ub4dc\ub294 \ud50c\ub798\uadf8\ub85c\uc368 word, numb, fork\uc5d0 \uac12\uc744 \uc9c0\uc815\ud558\uace0\uc790 \ud558\ub294 \uacbd\uc6b0\uc785\ub2c8\ub2e4. word\ub294 \ubb38\uc790\uc5f4, numb\ub294 \uc815\uc218\ud615, fork\ub294 \ube14\ub9b0\ud615\uc73c\ub85c \uc9c0\uc815\ud569\ub2c8\ub2e4.<\/p>\n<pre>\r\npackage main\r\n\r\nimport (\r\n    \"flag\"\r\n    \"fmt\"\r\n)\r\n\r\nfunc main() {\r\n    wordPtr := flag.String(\"word\", \"foo\", \"a string\")\r\n    numPtr := flag.Int(\"numb\", 42, \"an int\")\r\n    boolPtr := flag.Bool(\"fork\", false, \"a bool\")\r\n\r\n    flag.Parse()\r\n\r\n    fmt.Println(\"word: \", *wordPtr)\r\n    fmt.Println(\"numb: \", *numPtr)\r\n    fmt.Println(\"fork: \", *boolPtr)\r\n    fmt.Println(\"tail: \", flag.Args())\r\n}\r\n<\/pre>\n<p><P>\uc704\uc758 \ud504\ub85c\uadf8\ub7a8\uc744 \ucef4\ud30c\uc77c\ud574 \uc2e4\ud589 \ud30c\uc77c\ub85c cmd_flag.exe\uac00 \ub9cc\ub4e4\uc5b4\uc84c\ub2e4\uace0 \ud560 \ub54c, \uc55e\uc11c \uc5b8\uae09\ud55c \uac01 \ud50c\ub798\uadf8\uc5d0 \uac12\uc744 \uc9c0\uc815\ud558\uc5ec \uc2e4\ud589\ud55c \uc608\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/P><\/p>\n<pre>\r\nd:\\__Working__\\tstGo\\cmd_flags>cmd_flags.exe -word=Hello -numb=23 -fork=true\r\nword:  Hello\r\nnumb:  23\r\nfork:  true\r\ntail:  []\r\n\r\nd:\\__Working__\\tstGo\\cmd_flags>cmd_flags.exe -word=\"Hello World\" -numb=23 -fork=true\r\nword:  Hello World\r\nnumb:  23\r\nfork:  true\r\ntail:  []\r\n\r\nd:\\__Working__\\tstGo\\cmd_flags>cmd_flags.exe -word=\"Hello World\" -numb=23 -fork=true a1 a2 a3\r\nword:  Hello World\r\nnumb:  23\r\nfork:  true\r\ntail:  [a1 a2 a3]\r\n\r\nd:\\__Working__\\tstGo\\cmd_flags>cmd_flags.exe -word=\"Hello World\" -numb=a -fork=true\r\ninvalid value \"a\" for flag -numb: strconv.ParseInt: parsing \"a\": invalid syntax\r\nUsage of cmd_flags.exe:\r\n  -fork\r\n        a bool\r\n  -numb int\r\n        an int (default 42)\r\n  -word string\r\n        a string (default \"foo\")\r\n\r\nd:\\__Working__\\tstGo\\cmd_flags>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Go\uc5d0\uc11c \ub9cc\ub4e4\uc5b4\uc9c4 \uc2e4\ud589 \ud30c\uc77c\uc744 \uc2e4\ud589\ud560 \ub54c, \uba85\ub839\uc904\uc5d0 \uc785\ub825\ud55c \ud50c\ub798\uadf8 \uac12\uc744 \uc27d\uac8c \uc5bb\uae30 \uc704\ud574 \uc81c\uacf5\ud558\ub294 flag \ud328\ud0a4\uc9c0 \uc0ac\uc6a9\uc5d0 \ub300\ud55c \ucf54\ub4dc\ub97c \uc815\ub9ac\ud574 \ubd05\ub2c8\ub2e4. \uc544\ub798\uc758 \ucf54\ub4dc\ub294 \ud50c\ub798\uadf8\ub85c\uc368 word, numb, fork\uc5d0 \uac12\uc744 \uc9c0\uc815\ud558\uace0\uc790 \ud558\ub294 \uacbd\uc6b0\uc785\ub2c8\ub2e4. word\ub294 \ubb38\uc790\uc5f4, numb\ub294 \uc815\uc218\ud615, fork\ub294 \ube14\ub9b0\ud615\uc73c\ub85c \uc9c0\uc815\ud569\ub2c8\ub2e4. package main import ( &#8220;flag&#8221; &#8220;fmt&#8221; ) func main() { wordPtr := flag.String(&#8220;word&#8221;, &#8220;foo&#8221;, &#8220;a string&#8221;) numPtr &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=2445\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[Golang] \uba85\ub839\uc904\uc5d0 \ub300\ud55c \ud50c\ub798\uadf8 \uc5bb\uae30(Command-Line Flag)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[113],"tags":[],"class_list":["post-2445","post","type-post","status-publish","format-standard","hentry","category-golang"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2445"}],"version-history":[{"count":1,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2445\/revisions"}],"predecessor-version":[{"id":2778,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/2445\/revisions\/2778"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2445"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}