<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shanmukh Sista</title>
    <description>The latest articles on DEV Community by Shanmukh Sista (@shanmukhsista).</description>
    <link>https://dev.to/shanmukhsista</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F665189%2Fba692e93-22bd-46f7-b028-0259c6d44757.png</url>
      <title>DEV Community: Shanmukh Sista</title>
      <link>https://dev.to/shanmukhsista</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shanmukhsista"/>
    <language>en</language>
    <item>
      <title>CLIs Made Simple : Guide to writing a beautiful CLI in GoLang</title>
      <dc:creator>Shanmukh Sista</dc:creator>
      <pubDate>Fri, 20 Aug 2021 14:05:22 +0000</pubDate>
      <link>https://dev.to/shanmukhsista/clis-made-simple-guide-to-writing-a-beautiful-cli-in-golang-2l1m</link>
      <guid>https://dev.to/shanmukhsista/clis-made-simple-guide-to-writing-a-beautiful-cli-in-golang-2l1m</guid>
      <description>&lt;p&gt;Over the last few years, i've been fascinated by the type of Applications and services one could write in Go. Using GoLang I've implemented RPC Services, REST APIs, Web UIs and Cloud Functions using extremely simple programming paradigms. The main reason i enjoy GoLang is the simplicity it has to offer. At the same time, it's extremely powerful to write a wide variety of applications. It is known to be a systems language, but it's not limited in any way.&lt;/p&gt;

&lt;p&gt;In this article, i'll guide you through a simple CLI app that can be written in less than 30 minutes in GoLang. Before we dive deeper, here are the requirements to work on this.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GoLang  ( 1.16 -&lt;a href="https://golang.org/doc/install" rel="noopener noreferrer"&gt;https://golang.org/doc/install&lt;/a&gt; ) &lt;/li&gt;
&lt;li&gt;Text Editor ( &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;https://code.visualstudio.com/&lt;/a&gt; ) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This guide doesn't go in the details of Coding in GoLang. It gives a high level overview of implementing a CLI as a starting point to your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a New Project
&lt;/h2&gt;

&lt;p&gt;This is the first step for our application. To setup a new project, create a new folder on your system. Execute the commands below to get started.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir cliapp
# Create a Go Project.
go mod init github.com/shanmukhsista/cliapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a new Go Project. A file named &lt;code&gt;go.mod&lt;/code&gt; should be created after this.&lt;/p&gt;

&lt;p&gt;We'll be using Cobra ( &lt;a href="https://github.com/spf13/cobra" rel="noopener noreferrer"&gt;https://github.com/spf13/cobra&lt;/a&gt; ) to create our CLI. Another awesome library that helps with this whole process, and provides a lot of capabilities out of the box ( help text, cli argument parsing ...  )&lt;/p&gt;

&lt;p&gt;Run the following command to add Cobra as a Dependency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go get -u github.com/spf13/cobra
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Initialize Cobra CLI Project
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cobra init --pkg-name github.com/shanmukhsista/cliapp
Your Cobra applicaton is ready at ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fshanmukhsista.com%2Fcontent%2Fimages%2F2021%2F08%2Fcli-folder-structure.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fshanmukhsista.com%2Fcontent%2Fimages%2F2021%2F08%2Fcli-folder-structure.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upon successful execution, your folder structure should look like the image shown above. Below is a summary of these files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;main.go&lt;/code&gt; - This is the entry point for our app. Any initialization before the CLI runs can be done within this file. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cmd&lt;/code&gt; Folder - This folder contains all the commands, and sub commands as separate go files. Try executing the following command, and see how the folder structure changes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Add a root command 
cobra add setup
# Add a child command to the root command.
cobra add tests -p setupCmd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Time to Test our app!
&lt;/h3&gt;

&lt;p&gt;So far, our application doesn't have any specific logic. Let's build the app and see how our CLI looks like at this point. Run the following command to build and run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Build our app with 
go build -o cliapp main.go
./cliapp

$ ./cliapp
A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.

Usage:
  cliapp [command]

Available Commands:
  completion generate the autocompletion script for the specified shell
  help Help about any command
  setup A brief description of your command

Flags:
      --config string config file (default is $HOME/.cliapp.yaml)
  -h, --help help for cliapp
  -t, --toggle Help message for toggle

Use "cliapp [command] --help" for more information about a command.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the output that is generated by Cobra when your command is executed. Notice that the setup command is generated as a top level command. Try executing another command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./cliapp setup -h
A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.

Usage:
  cliapp setup [flags]
  cliapp setup [command]

Available Commands:
  tests A brief description of your command

Flags:
  -h, --help help for setup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add Some Logic And Parameters
&lt;/h2&gt;

&lt;p&gt;Until now, our application doesn't really do anything. Cobra gives  specific starting points where code can be written and application logic can be executed.&lt;/p&gt;

&lt;p&gt;Let's write some code within the setup method.&lt;/p&gt;

&lt;p&gt;It can be seen that all of the commands have their own files within the &lt;code&gt;cmd&lt;/code&gt; folder. To write some logic to the &lt;code&gt;setup&lt;/code&gt; command, try opening the file &lt;code&gt;cmd/setup.go&lt;/code&gt; and add code within the ( &lt;code&gt;Run: func(cmd *cobra.Command, args []string)&lt;/code&gt; block :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// setupCmd represents the setup command
var setupCmd = &amp;amp;cobra.Command{
    Use: "setup",
    Short: "A brief description of your command",
    Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
    Run: func(cmd *cobra.Command, args []string) {

        // Add any custom code here.
        // This gets executed whenever this command is called.

        fmt.Println("setup called")
    },
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where all the logic can go. In a production setting, this can act as an entry point to the package where the actual logic exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Parameters
&lt;/h3&gt;

&lt;p&gt;Practically speaking, every CLI app takes in one or more than one command line argument. Let's try to add one to our setup method. In this case, let's take an argument &lt;code&gt;--app-name&lt;/code&gt; as our argument. We'll print out this when our command executes.&lt;/p&gt;

&lt;p&gt;Define a new variable in &lt;code&gt;cmd/setup.go&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import (
    "fmt"

    "github.com/spf13/cobra"
)

var AppName string // Store App Name Argument
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The goal here is to parse &lt;code&gt;--app-name&lt;/code&gt; argument, and automatically assign it to the variable defined above. To do so, add the following command to the init method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
func init() {
    rootCmd.AddCommand(setupCmd)
    // Define a new flag for App Name
    setupCmd.Flags().StringVarP(&amp;amp;AppName, "app-name", "a", "", "App Name")

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now use this variable in the actual execution logic. In this case, we print the app name within the Run Method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Run: func(cmd *cobra.Command, args []string) {

        // Add any custom code here.
        // This gets executed whenever this command is called.

        fmt.Println("setup called with app name " + AppName)
    },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build and run the program to view App Name printed on the screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go build -o cliapp main.go
./cliapp setup --app-name "New CLI App"
setup called with app name New CLI App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This process can be repeated for any number of arguments, commands, and child commands. Cobra really simplifies a building CLIs to enable some powerful applications that can run in any environment. Built executables can be copied and run on any target system without any underlying VM / service.&lt;/p&gt;

</description>
      <category>tutorials</category>
      <category>go</category>
      <category>cli</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Host Ghost CMS as a Static Website  - Using Gatsby Ghost Template</title>
      <dc:creator>Shanmukh Sista</dc:creator>
      <pubDate>Thu, 19 Aug 2021 01:12:32 +0000</pubDate>
      <link>https://dev.to/shanmukhsista/host-ghost-cms-as-a-static-website-using-gatsby-ghost-template-14el</link>
      <guid>https://dev.to/shanmukhsista/host-ghost-cms-as-a-static-website-using-gatsby-ghost-template-14el</guid>
      <description>&lt;p&gt;I love Ghost CMS for creating content, and it is a personal favorite of mine. In this article, I'll show you how to use Ghost as a Dynamic backend for Creating and Writing content. In the end, I'll show on how to convert the content to a blazing fast static site using Gatsby.&lt;/p&gt;

&lt;p&gt;These are the steps which we will be executing in order to host a static site built from Ghost CMS.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Ghost Locally, configure, and publish Articles.&lt;/li&gt;
&lt;li&gt;Create a new Gatsby Static Site&lt;/li&gt;
&lt;li&gt;Connect Gatsby with Ghost Backend&lt;/li&gt;
&lt;li&gt;Test and Generate a Static Site for hosting.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Install Ghost Locally
&lt;/h2&gt;

&lt;p&gt;Requirements&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Nodejs &amp;gt; 14.15.0 ( Install Via NVM )&lt;/li&gt;
&lt;li&gt;NPM &amp;amp; Gatsby CLI
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir ghost-local &amp;amp;&amp;amp; cd ghost-local
# Switch Node Version if you have nvm
nvm use v14.17.0
npm install ghost-cli@latest -g
ghost install local

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A successful install should have the following message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ Checking system Node.js version - found v14.17.5
✔ Checking current folder permissions
✔ Checking memory availability
✔ Checking free space
✔ Checking for latest Ghost version
✔ Setting up install directory
☲ Downloading and installing Ghost v4.12.1 &amp;gt; Installing dependencies &amp;gt; [5/5] Building fresh packages...
✔ Downloading and installing Ghost v4.12.1
✔ Finishing install process
✔ Configuring Ghost
✔ Setting up instance
✔ Starting Ghost

Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/docs/config/#mail

------------------------------------------------------------------------------

Ghost was installed successfully! To complete setup of your publication, visit:

    http://localhost:2368/ghost/

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view installed sites , use &lt;code&gt;ghost ls&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ghost ls
┌─────────────┬──────────────────────────────┬─────────┬───────────────────────┬────────────────────────┬──────┬─────────────────┐
│ Name │ Location │ Version │ Status │ URL │ Port │ Process Manager │
├─────────────┼──────────────────────────────┼─────────┼───────────────────────┼────────────────────────┼──────┼─────────────────┤
│ ghost-local │ ~/personal/shanmukhsista.com │ 4.12.1 │ running (development) │ http://localhost:2368/ │ 2368 │ local │
└─────────────┴──────────────────────────────┴─────────┴───────────────────────┴────────────────────────┴──────┴─────────────────┘

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit &lt;a href="http://localhost:2368/" rel="noopener noreferrer"&gt;localhost:2368&lt;/a&gt; to view the site.&lt;/p&gt;

&lt;h3&gt;
  
  
  Time to Check In ( Recommended )
&lt;/h3&gt;

&lt;p&gt;The directory in which Ghost was installed acts as the root for all local content development. It's a good idea to check it in a private git repository.&lt;/p&gt;

&lt;p&gt;Keeping this Folder Checked in / Backed Up will help in generating the static site every time content is added / updated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a New Static Site
&lt;/h2&gt;

&lt;p&gt;Now that ghost has been setup on a local machine, it's time to host it on the internet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clone a Site Template
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create a new Directory. This is where the output of your site will reside.
gatsby new static-site https://github.com/TryGhost/gatsby-starter-ghost.git
cd static-site

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Connect Gatsby with Ghost Backend
&lt;/h3&gt;

&lt;p&gt;Our static Site will be pulling content from the Ghost that was installed locally. This requires a new API Integration.&lt;/p&gt;

&lt;p&gt;Navigate to &lt;a href="http://localhost:2368/ghost/#/integrations" rel="noopener noreferrer"&gt;http://localhost:2368/ghost/#/integrations&lt;/a&gt; to generate a new API Key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fshanmukhsista.com%2Fcontent%2Fimages%2F2021%2F08%2FScreen-Shot-2021-08-18-at-5.24.34-PM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fshanmukhsista.com%2Fcontent%2Fimages%2F2021%2F08%2FScreen-Shot-2021-08-18-at-5.24.34-PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upon Generation, an API key and a URL should be visible.Copy these keys for the  next step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fshanmukhsista.com%2Fcontent%2Fimages%2F2021%2F08%2FScreen-Shot-2021-08-18-at-5.29.37-PM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fshanmukhsista.com%2Fcontent%2Fimages%2F2021%2F08%2FScreen-Shot-2021-08-18-at-5.29.37-PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Update API keys for the Static Side Project
&lt;/h3&gt;

&lt;p&gt;Navigate to the static site folder, and open the file &lt;code&gt;.ghost.json&lt;/code&gt; file. Replace the &lt;code&gt;apiUrl&lt;/code&gt; and &lt;code&gt;contentApiKey&lt;/code&gt; that was just generated.&lt;/p&gt;

&lt;p&gt;This is the part where we tell Gatsby to pull content from GHOST.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "development": {
    "apiUrl": "http://localhost:2368",
    "contentApiKey": "xxx"
  },
  "production": {
   "apiUrl": "http://localhost:2368",
    "contentApiKey": "xxx"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test &amp;amp; Deploy
&lt;/h2&gt;

&lt;p&gt;Test by Executing the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gatsby develop

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Build a Static Site for Hosting
&lt;/h3&gt;

&lt;p&gt;The last step is to build our site and generate static Assets. This allows us to host the site on any of the following :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SITEURL=https://site.com gatsby build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gatsby should be able to compile and Build a final website available in &lt;code&gt;public&lt;/code&gt; directory. Copy all files here to a static site hosting space.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Google Firebase Hosting&lt;/li&gt;
&lt;li&gt;GCS Hosting&lt;/li&gt;
&lt;li&gt;Netlify&lt;/li&gt;
&lt;li&gt;DigitalOcean&lt;/li&gt;
&lt;li&gt;Github Pages&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Or any other provider that has static site hosting supported.&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>ghost</category>
      <category>cms</category>
      <category>personalblog</category>
    </item>
  </channel>
</rss>
