Skip to content

Instantly share code, notes, and snippets.

@rudifa
Last active May 28, 2023 11:34
Show Gist options
  • Select an option

  • Save rudifa/49b3530a0bc9536a67fda44a1a14eacf to your computer and use it in GitHub Desktop.

Select an option

Save rudifa/49b3530a0bc9536a67fda44a1a14eacf to your computer and use it in GitHub Desktop.

Revisions

  1. rudifa revised this gist May 24, 2023. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions gopro
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ done
    shift $((OPTIND - 1))

    if [ -z "$1" ]; then
    echo "Usage: $0 [-c] dir_name"
    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
    package main
    import "fmt"
    import "fmt"
    func main() {
    fmt.Println("Here we go")
    }
    func main() {
    fmt.Println("Here we go")
    }
    EOF

    if [ "$c_flag" = true ]; then
  2. rudifa created this gist May 24, 2023.
    46 changes: 46 additions & 0 deletions gopro
    Original 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