Skip to content

Commit

Permalink
Merge Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Alder Whiteford authored and Alder Whiteford committed May 1, 2024
2 parents 47ec5f8 + f2d780d commit 3a99568
Show file tree
Hide file tree
Showing 53 changed files with 1,338 additions and 1,055 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
- If you get an error about `expo-cli` not being installed, run `yarn global add expo-cli` and then run `yarn install` again.

```console
cd server
cd backend
go get ./...
```

Expand Down Expand Up @@ -119,7 +119,7 @@ To create a new migration, you can use the CLI

### SAC CLI

To install use `./scripts/install_cli.sh` and then run `sac` to see all commands.
To install use `./install_cli.sh` and then run `sac` to see all commands.

# Git Flow

Expand Down
2 changes: 1 addition & 1 deletion cli/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ linters:

linters-settings:
whitespace:
multi-func: true
multi-func: true
62 changes: 62 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# SAC (Student Activity Calendar) CLI

[![CLI](https://github.com/GenerateNU/sac/actions/workflows/cli.yml/badge.svg)](https://github.com/GenerateNU/sac/actions/workflows/cli.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/GenerateNU/sac/cli)](https://goreportcard.com/report/github.com/GenerateNU/sac/cli)
[![License](https://img.shields.io/github/license/GenerateNU/sac)](https://github.com/GenerateNU/sac/blob/main/LICENSE)



## Introduction
The SAC CLI is a tool designed to help manage and automate tasks for the GenerateNU Student Activity Calendar platform. It provides a comprehensive suite of commands for formatting, testing, linting, running, and managing databases and other configurations essential for the SAC platform.

## Table of Contents

1. [Installation](#installation)
2. [Usage](#usage)
3. [Available Commands](#available-commands)
4. [Command Aliases](#command-aliases)
5. [Dependencies](#dependencies)

## Installation

To install the SAC CLI, clone the repository and run the following script from the root of the application:

```bash
./install_cli.sh
```

## Usage

To use the SAC CLI, you can run it with various flags or commands:

```bash
sac [flags]
sac [command]
```

## Available Commands

- **completion**: Generate the autocompletion script for the specified shell.
- **database**: Database management commands.
- **format**: Formatting commands.
- **help**: Help about any command.
- **lint**: Linting commands.
- **run**: Run commands for backend and frontend.
- **setup**: Installs and sets up the project. (WIP)
- **swagger**: Run swagger initialization for backend openapi spec.
- **test**: Testing commands.

For more detailed information about a command, use:

```bash
sac [command] --help
```

## Command Aliases

Several commands in the SAC CLI are equipped with short aliases to make them quicker and easier to use. For example, a command like `sac format frontend dashboard` which is pretty lengthy can be shortened to `sac f fe d`.

## Dependencies

- `golangci-lint`: A linter aggregator for Go, ensuring code quality.
- `gofumpt`: A stricter formatter for Go code, ensuring consistency.
81 changes: 81 additions & 0 deletions cli/cmd/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cmd

import (
"fmt"
"os"

"github.com/GenerateNU/sac/cli/helpers"
"github.com/spf13/cobra"
)

var dbCmd = &cobra.Command{
Use: "database",
Aliases: []string{"db"},
Short: "Database management commands",
}

func init() {
rootCmd.AddCommand(dbCmd)
dbCmd.AddCommand(dbInitCmd)
dbCmd.AddCommand(dbDownCmd)
dbCmd.AddCommand(dbResetCmd)
dbCmd.AddCommand(dbInsertCmd)
}

var dbInitCmd = &cobra.Command{
Use: "init",
Short: "Initialize the database",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.InitDB()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var dbDownCmd = &cobra.Command{
Use: "down",
Short: "Migrate down the database",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.DownDB()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var dbResetCmd = &cobra.Command{
Use: "reset",
Short: "Reset the database",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.DownDB()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

err = helpers.InitDB()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var dbInsertCmd = &cobra.Command{
Use: "insert",
Short: "Insert mock data into the database",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.InsertDB()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
131 changes: 131 additions & 0 deletions cli/cmd/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package cmd

import (
"fmt"
"os"
"os/exec"

"github.com/GenerateNU/sac/cli/helpers"
"github.com/spf13/cobra"
)

var formatCmd = &cobra.Command{
Use: "format",
Aliases: []string{"f"},
Short: "Formatting commands",
}

func init() {
rootCmd.AddCommand(formatCmd)
formatCmd.AddCommand(formatFrontendCmd)
formatCmd.AddCommand(formatBackendCmd)
formatCmd.AddCommand(formatCliCmd)

formatFrontendCmd.AddCommand(formatWebCmd)
formatFrontendCmd.AddCommand(formatMobileCmd)
formatFrontendCmd.AddCommand(formatDashboardCmd)
formatFrontendCmd.AddCommand(formatLibCmd)
}

var formatFrontendCmd = &cobra.Command{
Use: "frontend",
Aliases: []string{"fe"},
Short: "Frontend formatting commands",
}

var formatWebCmd = &cobra.Command{
Use: "web",
Aliases: []string{"w"},
Short: "Frontend web formatting commands",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.Execute(exec.Command("yarn", "run", "format"), helpers.WEB_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var formatMobileCmd = &cobra.Command{
Use: "mobile",
Aliases: []string{"m"},
Short: "Formats the frontend mobile",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.Execute(exec.Command("yarn", "run", "format"), helpers.MOBILE_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var formatDashboardCmd = &cobra.Command{
Use: "dashboard",
Aliases: []string{"d"},
Short: "Formats the frontend dashboard",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.Execute(exec.Command("yarn", "run", "format"), helpers.DASHBOARD_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var formatLibCmd = &cobra.Command{
Use: "lib",
Aliases: []string{"l"},
Short: "Formats the frontend lib",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := helpers.Execute(exec.Command("yarn", "run", "format"), helpers.LIB_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var formatBackendCmd = &cobra.Command{
Use: "backend",
Short: "Formats the backend",
Aliases: []string{"be"},
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
_, err := exec.LookPath("gofumpt")
if err != nil {
fmt.Println("gofumpt is not installed. Please run the following command to install it:")
fmt.Println("go install mvdan.cc/gofumpt@latest")
os.Exit(1)
}

err = helpers.Execute(exec.Command("gofumpt", "-l", "-w", "."), helpers.BACKEND_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var formatCliCmd = &cobra.Command{
Use: "cli",
Short: "Formats the cli",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
_, err := exec.LookPath("gofumpt")
if err != nil {
fmt.Println("gofumpt is not installed. Please run the following command to install it:")
fmt.Println("go install mvdan.cc/gofumpt@latest")
os.Exit(1)
}

err = helpers.Execute(exec.Command("gofumpt", "-l", "-w", "."), helpers.CLI_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
Loading

0 comments on commit 3a99568

Please sign in to comment.