Last active
May 28, 2023 11:34
-
-
Save rudifa/49b3530a0bc9536a67fda44a1a14eacf to your computer and use it in GitHub Desktop.
Revisions
-
rudifa revised this gist
May 24, 2023 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ done shift $((OPTIND - 1)) if [ -z "$1" ]; then echo "Usage: $(basename "$0") [-c] dir_name" echo "Creates a new directory, initializes a Go module, and creates a main.go file." echo "Options:" echo " -c, --cobra Initialize a Cobra CLI project in the module" @@ -30,13 +30,13 @@ else # Initialize Go module go mod init "$dir_name" cat <<EOF >main.go package main import "fmt" func main() { fmt.Println("Here we go") } EOF if [ "$c_flag" = true ]; then -
rudifa created this gist
May 24, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ #!/bin/bash # Create a new Go project with a main.go file and a Go module # Option -c, --cobra: Initialize a Cobra CLI project in the module while getopts ":c" opt; do case $opt in c) c_flag=true ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; esac done shift $((OPTIND - 1)) if [ -z "$1" ]; then echo "Usage: $0 [-c] dir_name" echo "Creates a new directory, initializes a Go module, and creates a main.go file." echo "Options:" echo " -c, --cobra Initialize a Cobra CLI project in the module" else dir_name="$1" mkdir "$dir_name" && cd "$dir_name" # Initialize Go module go mod init "$dir_name" cat <<EOF >main.go package main import "fmt" func main() { fmt.Println("Here we go") } EOF if [ "$c_flag" = true ]; then # Initialize cobra-cli cobra-cli init fi fi