{"id":292,"date":"2026-05-01T09:00:00","date_gmt":"2026-05-01T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/"},"modified":"2026-10-10T21:21:00","modified_gmt":"2026-10-10T15:51:00","slug":"go-flag-package-cli","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/","title":{"rendered":"Go Flag Package: Build Command Line Tools"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Go flag package turns a plain program into a command line tool with options and a help screen. In this post, you will define flags, read extra arguments, write a custom help message and add subcommands. Each idea comes with a short example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the last lesson, <a href=\"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/\">Go environment variables for configuration<\/a> set options from outside the program. Flags do the same job, but per run. We also use pointers a lot here, so <a href=\"https:\/\/smitabharat.com\/blog\/go-pointers-explained\/\">pointers in Go<\/a> is a quick refresher.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is the Go Flag Package?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A command line flag is an option you type after the program name, such as <code>-n 3<\/code> or <code>-loud<\/code>. The standard <code>flag<\/code> package reads those options, converts them to the right type and prints help when something is wrong.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of ordering coffee. The drink is always coffee, but you add options: large, oat milk, extra shot. Flags are those options for your program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Defining Flags with the Go Flag Package<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>name := flag.String(\"name\", \"World\", \"who to greet\")\ntimes := flag.Int(\"n\", 1, \"how many times to greet\")\nloud := flag.Bool(\"loud\", false, \"print in capital letters\")\nflag.Parse()\n\nmsg := \"Hello, \" + *name + \"!\"\nif *loud {\n\tmsg = strings.ToUpper(msg)\n}\nfor i := 0; i &lt; *times; i++ {\n\tfmt.Println(msg)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each function takes a name, a default value and a help text. It returns a pointer, so you read the value with <code>*name<\/code>. Most importantly, call <code>flag.Parse()<\/code> before reading any flag.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ go build -o greet .\n$ .\/greet\nHello, World!\n$ .\/greet -name=Asha -n 2 -loud\nHELLO, ASHA!\nHELLO, ASHA!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The diagram below shows how the Go flag package splits a command into flags and leftover arguments.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-diagram-1024x640.png\" alt=\"Go Flag Package diagram showing a command split into flags and leftover arguments by flag.Parse\" class=\"wp-image-275\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>flag.Parse reads each option into its variable, and everything after the flags stays in flag.Args.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Flag Syntax the Go Flag Package Accepts<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>You type<\/th><th>Works?<\/th><\/tr><\/thead><tbody><tr><td><code>-name=Asha<\/code><\/td><td>Yes<\/td><\/tr><tr><td><code>-name Asha<\/code><\/td><td>Yes, except for bool flags<\/td><\/tr><tr><td><code>--name Asha<\/code><\/td><td>Yes, two dashes also work<\/td><\/tr><tr><td><code>-loud<\/code><\/td><td>Yes, sets a bool to true<\/td><\/tr><tr><td><code>-loud=false<\/code><\/td><td>Yes, the only way to set a bool to false<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Reading Extra Arguments<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/greet --name Ravi go is fun\nHello, Ravi!\nextra args: [go is fun] 3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After parsing, <code>flag.Args()<\/code> returns the words that were not flags, and <code>flag.NArg()<\/code> counts them. However, parsing stops at the first non-flag word. So <code>.\/greet go -name=Asha<\/code> treats <code>-name=Asha<\/code> as a plain argument.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Flags Bound to Variables<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>var wait time.Duration\nflag.DurationVar(&amp;wait, \"wait\", 0, \"pause between greetings\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>Var<\/code> versions write into a variable you already have. In addition, <code>flag.Duration<\/code> understands values like <code>500ms<\/code> or <code>2s<\/code> for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Custom Help Text<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>flag.Usage = func() {\n\tfmt.Fprintf(os.Stderr, \"Usage: greet [flags] [extra words]\\n\")\n\tflag.PrintDefaults()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/greet -h\nUsage: greet [flags] [extra words]\n  -loud\n    \tprint in capital letters\n  -n int\n    \thow many times to greet (default 1)\n  -name string\n    \twho to greet (default \"World\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Running with <code>-h<\/code> prints this help for free, and the program then exits with status 0. Without a custom <code>Usage<\/code>, Go prints a shorter title based on the program name. So a custom message is worth a few lines, because it tells users what the extra words mean. Notice that the Go flag package also shows each type and default value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Subcommands with FlagSet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>switch os.Args[1] {\ncase \"add\":\n\taddCmd := flag.NewFlagSet(\"add\", flag.ExitOnError)\n\ttitle := addCmd.String(\"title\", \"\", \"task title\")\n\taddCmd.Parse(os.Args[2:])\n\tfmt.Println(\"adding task:\", *title)\ncase \"list\":\n\tlistCmd := flag.NewFlagSet(\"list\", flag.ExitOnError)\n\tdone := listCmd.Bool(\"done\", false, \"show finished tasks\")\n\tlistCmd.Parse(os.Args[2:])\n\tfmt.Println(\"listing tasks, done =\", *done)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/tasks add -title \"Learn flags\"\nadding task: Learn flags\n$ .\/tasks list -done\nlisting tasks, done = true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Tools like <code>git<\/code> and <code>go<\/code> use subcommands. Each <code>FlagSet<\/code> holds its own flags, so <code>add<\/code> and <code>list<\/code> never clash.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with the Go Flag Package<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td>flag provided but not defined: -x<\/td><td>The user typed an unknown flag.<\/td><td>Check the spelling, or run with -h.<\/td><\/tr><tr><td>invalid value &#8220;abc&#8221; for flag -n: parse error<\/td><td>Text was given to an int flag.<\/td><td>Pass a number.<\/td><\/tr><tr><td>flag needs an argument: -name<\/td><td>The flag had no value.<\/td><td>Write <code>-name=Asha<\/code>.<\/td><\/tr><tr><td>Flags always show defaults<\/td><td><code>flag.Parse()<\/code> was never called.<\/td><td>Call it before reading flags.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">On these errors the program prints the help and exits with status 2. Command line questions also appear in interviews, so practise with my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they stay accurate and up to date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/flag\">flag package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/os#pkg-variables\">os package: Args<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Go flag package parses command line options into typed values.<\/li>\n\n\n\n<li>Each flag function returns a pointer, so read it with <code>*<\/code>.<\/li>\n\n\n\n<li>Always call <code>flag.Parse()<\/code> before using flags.<\/li>\n\n\n\n<li><code>flag.Args()<\/code> holds the leftover words after the flags.<\/li>\n\n\n\n<li>Use <code>flag.NewFlagSet<\/code> to build subcommands.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can now build handy command line tools. Next, we will find out where a program spends its time and memory with profiling and pprof.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-profiling-pprof-guide\/\">Go Profiling with pprof for Beginners<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>The Go flag package turns a plain program into a command line tool with options and a help screen. In this post, you will&hellip;<\/p>\n","protected":false},"author":1,"featured_media":274,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[58,11,23,21],"swapz_series":[],"class_list":["post-292","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-cli","tag-go-lang","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Flag Package: Build Command Line Tools<\/title>\n<meta name=\"description\" content=\"Learn the Go flag package with simple examples: define string, int and bool flags, read extra arguments, customise help and add subcommands.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Flag Package: Build Command Line Tools\" \/>\n<meta property=\"og:description\" content=\"Learn the Go flag package with simple examples: define string, int and bool flags, read extra arguments, customise help and add subcommands.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-01T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:51:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Flag Package: Build Command Line Tools\",\"datePublished\":\"2026-05-01T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/\"},\"wordCount\":594,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-flag-package-cli-featured.png\",\"keywords\":[\"Go CLI\",\"Go Lang\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/\",\"name\":\"Go Flag Package: Build Command Line Tools\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-flag-package-cli-featured.png\",\"datePublished\":\"2026-05-01T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:00+00:00\",\"description\":\"Learn the Go flag package with simple examples: define string, int and bool flags, read extra arguments, customise help and add subcommands.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-flag-package-cli-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-flag-package-cli-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Flag Package featured image: cards for string flags, number flags and help text\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-flag-package-cli\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Flag Package: Build Command Line Tools\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Flag Package: Build Command Line Tools","description":"Learn the Go flag package with simple examples: define string, int and bool flags, read extra arguments, customise help and add subcommands.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/","og_locale":"en_US","og_type":"article","og_title":"Go Flag Package: Build Command Line Tools","og_description":"Learn the Go flag package with simple examples: define string, int and bool flags, read extra arguments, customise help and add subcommands.","og_url":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-01T03:30:00+00:00","article_modified_time":"2026-10-10T15:51:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Flag Package: Build Command Line Tools","datePublished":"2026-05-01T03:30:00+00:00","dateModified":"2026-10-10T15:51:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/"},"wordCount":594,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-featured.png","keywords":["Go CLI","Go Lang","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/","url":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/","name":"Go Flag Package: Build Command Line Tools","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-featured.png","datePublished":"2026-05-01T03:30:00+00:00","dateModified":"2026-10-10T15:51:00+00:00","description":"Learn the Go flag package with simple examples: define string, int and bool flags, read extra arguments, customise help and add subcommands.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-flag-package-cli-featured.png","width":2400,"height":1260,"caption":"Go Flag Package featured image: cards for string flags, number flags and help text"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Flag Package: Build Command Line Tools"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=292"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":307,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/292\/revisions\/307"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/274"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=292"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}