Skip to content

Commit

Permalink
Add version flag and installation script (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinag08 authored Feb 29, 2024
1 parent e97273a commit fd499a4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jobs:
echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV
- name: Build
run: |
go build -o snd-${{ matrix.os }}-${{ matrix.arch }} ./cmd/snd-cli
version=$(git describe --tags --abbrev=7)
go build -o snd-${{ matrix.os }}-${{ matrix.arch }} ./cmd/snd-cli -ldflags="-X 'github.com/SneaksAndData/snd-cli-go/blob/main/cmd/snd-cli/main.version=$version'"
- name: Import Secrets
uses: hashicorp/[email protected]
with:
Expand Down
4 changes: 4 additions & 0 deletions cmd/snd-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import (
"snd-cli/pkg/cmd/root"
)

var version = "v0.0.0"

func main() {
rootCmd, _ := root.NewCmdRoot()
rootCmd.Version = version
rootCmd.SetVersionTemplate(fmt.Sprintf("snd-cli version %s", version))
err := rootCmd.Execute()
if err != nil {
fmt.Println("Error: ", err)
Expand Down
56 changes: 56 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
# Installation script for SnD CLI
echo "Determining target OS and architecture..."
ARCH=$(uname -m)
if [[ "$OSTYPE" =~ ^darwin && "$ARCH" =~ arm64 ]]; then
bin_name=snd-darwin-arm64
elif [[ "$OSTYPE" =~ ^linux ]]; then
if [[ "$ARCH" =~ arm64 ]]; then
bin_name=snd-linux-arm64
elif [[ "$ARCH" =~ amd64 ]]; then
bin_name=snd-linux-amd64
elif [[ "$OSTYPE" =~ ^linux && "$ARCH" =~ amd64 ]]; then
bin_name=snd-windows-amd64
fi
else
echo "Error: Unsupported OS type or architecture: $OSTYPE $ARCH "
exit 1
fi
echo "Target OS: $OSTYPE"
echo "Target ARCH: $ARCH"

BUNDLE_URL="https://esddatalakeproduction.blob.core.windows.net/dist/snd-cli-go/$bin_name"

# Define base path for the application
base_path="$HOME/.local/snd-cli"
mkdir -p "$base_path"

# Check if az cli is installed
echo "Check if Azure CLI is installed..."
if ! command -v az &> /dev/null
then
echo "az cli is not installed. Please install it from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli"
exit
fi

# Login into azure
echo "Please log in to Azure..."
az login

echo "Downloading the binary from $BUNDLE_URL"
# Get file
az storage blob download --blob-url $BUNDLE_URL --auth-mode login --file "$base_path/$bin_name"

chmod +x "$base_path/$bin_name"

if [ -e "$HOME/.local/bin/snd" ]; then
echo "Removing symlink..."
rm $HOME/.local/bin/snd
fi

# Create a symbolic link to the application
echo "Creating the symlink..."
ln -s "$base_path/$bin_name" "$HOME/.local/bin/snd"

echo "Please restart your terminal for the changes to take effect."
echo "After restarting, you can try running 'snd --help'. :)"
6 changes: 1 addition & 5 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ func NewCmdRoot() (*cobra.Command, error) {
Use: "snd <service command group> <service command> [flags]",
Short: "SnD CLI",
Long: `SnD CLI is a tool for interacting with various internal and external services in Sneaks & Data.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// TODO: Check that the user is authenticated before running most commands
// fmt.Println("To get started with SnD CLI, please run: snd login")
return nil
},
}

cmd.AddGroup(&cobra.Group{
ID: "auth",
Title: "Auth Commands",
Expand Down

0 comments on commit fd499a4

Please sign in to comment.