Typical cobra based app

// main.go

package main

import (

func main() {

Flags parse

First we have define variables

package cmd

var (
  title string
  description string
  rootCmd = &cobra.Command{
    Use: "blabla",
    Run: func(cmd *cobra.Command, args []string) {
      // your logic live there, right here!
      // you can directly access above variables

// called by main.go
func Execute() {

And then, parse them

func init() {
  rootCmd.PersistentFlags().StringVarP(&title, "title", "t", "", "Post title")
  rootCmd.PersistentFlags().StringVarP(&description, "description", "d", "", "Post descritption")
  rootCmd.PersistentFlags().StringVarP(&layout, "layout", "l", "post", "Post layout")
  rootCmd.PersistentFlags().StringArrayVarP(&keywords, "keywords", "k", []string{}, "Post keywords")