Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
branches:
- master

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Set version from commit count
run: echo "GORELEASER_CURRENT_TAG=v0.$(git rev-list --count HEAD)" >> $GITHUB_ENV

- uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@
!sce.bat
!sce.sh
!create_user.txt
!LICENSE
!main.go
!go.mod
!go.sum
!cmd/
!cmd/**
!internal/
!internal/**
!.goreleaser.yaml
!.github/
!.github/**
!install.sh
!install.ps1
25 changes: 25 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2

builds:
- main: .
binary: sce
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64

archives:
- format: binary
name_template: "sce-{{ .Os }}-{{ .Arch }}"

changelog:
use: github-native

release:
make_latest: true
name_template: "v{{ .Version }}"
135 changes: 57 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,96 @@
Command line tool to run any of the SCE projects. Works on Windows, Mac and
Linux. Available with the `sce` command.

## Setup
⚠️ **IMPORTANT WARNING**: If your Windows username contains spaces (e.g. "John Smith"), DO NOT install this in your user directory. Follow these special instructions instead:
1. Open File Explorer and go to the C: drive
2. Create a new folder called `SCE`
3. Open Command Prompt or PowerShell and run:
```
cd C:\SCE
git clone https://github.com/SCE-Development/SCE-CLI.git
```
## Prerequisites

For users without spaces in their username, you can proceed with the normal installation:
- [Docker](https://www.docker.com/)

Before starting, be sure you have Docker installed! This tool
runs SCE's projects with Docker.
## Setup

Clone this repository to your computer with
```
git clone https://github.com/SCE-Development/SCE-CLI.git
### Mac/Linux

Install with one command:
```sh
curl -sSL https://raw.githubusercontent.com/SCE-Development/SCE-CLI/master/install.sh | sh
```
Next, we will add the `sce` command to your terminal.

This downloads the correct binary for your system and installs it to `/usr/local/bin/sce`.

### Windows
You will need to add the location where the batch file is to your path. To do
this:
1. Copy the path where `SCE-CLI` is installed. The path should look like
```
C:\Users\<username>\path\to\SCE-CLI\
```
2. We need to edit (your env vars or something) we can do this with:
- Press `Window + R` to open the Windows Run prompt.
- Type in `sysdm.cpl` and click `OK`.
![image](https://phoenixnap.com/kb/wp-content/uploads/2021/04/setting-environment-variables-in-windows-06.png)
- Then go to the `Advanced` tab and click `Environment Variables`:
![image](https://phoenixnap.com/kb/wp-content/uploads/2021/04/setting-environment-variables-in-windows-07.png)
- Click on path in `System variables`
![edit_path](https://user-images.githubusercontent.com/10038262/180634975-6a7c7947-5560-4df6-bd5a-3d8bda033c70.png)
- Add the location where `SCE-CLI` is installed from earlier into
this path (see highlighted)
![path](https://user-images.githubusercontent.com/10038262/180634962-abd4ba91-30a2-47e7-8c50-4cc26a41b669.png)
3. After doing so, typing `sce` in the Command Prompt
should work, and the help page should show like below:
![eb2015026b076e7b31a8caa2ff8f2e55](https://user-images.githubusercontent.com/10038262/180635207-2ea70c08-003f-4f59-95f8-35817bc6a51b.png)

### Mac/Linux
1. cd into the `SCE-CLI`
2. Add an alias to your terminals config file like:
```sh
# for linux
./sce.sh completion >> ~/.bashrc
Run in PowerShell:
```powershell
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/SCE-Development/SCE-CLI/master/install.ps1" -UseBasicParsing | Invoke-Expression
```

### Verify

# for mac, first run the below command
echo $SHELL
# if the above is /bin/bash
./sce.sh completion >> ~/.bash_profile
# if the above is /bin/zsh
./sce.sh completion >> ~/.zshrc
After installing, open a new terminal and run:
```
sce --help
```
3. After doing the above, making a new terminal and typing `sce` should work.

## Usage
To use the script, you use the command `sce` with a command and repo name
The commands that you can run are: clone, link, run.
Alternatively, just run the command `sce` to see the usages in the terminal.
Use the command `sce` with a command and repo name.
Run `sce --help` to see all available commands.

### Repo Names
The name of the repositories are (the nicknames are alternate names you can use in the command):
core-v4 (nicknames: core-v4, corev4, cv4, c4, c)
quasar (nicknames: quasar, q, idsmile)
sarah (nicknames: sarah, sce-discord-bot, discord-bot, discord, bot, s, d)
Each repo has nicknames you can use interchangeably:

| Repo | Nicknames |
|------|-----------|
| Clark | clark, dog, clrk, ck, c |
| MongoDB | mongo, db, mongodb |
| Quasar | quasar, q, idsmile |
| SCE-discord-bot | sarah, sce-discord-bot, discord-bot, discord, bot, s, d |
| cleezy | cleezy, url, z |
| SCEta | sceta, transit |

### Clone
To clone an SCE project from GitHub, simply enter
Clone an SCE project from GitHub:
```
sce clone <project> [--ssh]
```
The repository will be cloned from wherever the command was ran.
Project names can be `quasar`, `core-v4`, `discord` etc. See the above repo
names section for all options.

The `--ssh` parameter can be optionally added after the project name.
Supplying this will clone the repo with the GitHub SSH URL over the
HTTPS one.
The `--ssh` flag clones using the SSH URL instead of HTTPS.

### Link
To link a sce repo to your directory where you are running the command, simply enter
Link a repo directory to the sce tool (run from inside the repo):
```
sce link <project>
```
Project names can be `quasar`, `core-v4`, `discord` etc. See the above repo
names section for all options.

### Run
To run an SCE project, simply enter

Run an SCE project with Docker:
```
sce run <project>
```
where project can be `quasar`, `core-v4`, `discord` etc. See the above repo
names section for all options.
To start only MongoDB:
```
sce run db
```

### Setup
Copy config.example.json to config.json for a project:
```
sce setup <project>
```

### Create
This will create a test account when running the SCE website locally. Before running,
make sure you have MongoDB running with:
Create a test account for the SCE website. Make sure MongoDB is running first:
```
sce run db
```
Then, run the below command:
Then create a user:
```
sce create
sce create [level]
```
After running the SCE website locally, ensure you can log in with the email
`test@one.sce` and password `sce`

Levels: `admin` (default), `officer`, `member`, `nonmember`, `pending`, `banned`.

Log in with the generated email and password `sce`.

### Lint
Run eslint --fix on running containers (Clark and SCE-discord-bot only):
```
sce lint <project>
```
Make sure the project is running with `sce run` first.
44 changes: 44 additions & 0 deletions cmd/clone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmd

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

"github.com/SCE-Development/SCE-CLI/internal"
"github.com/spf13/cobra"
)

var sshFlag bool

var cloneCmd = &cobra.Command{
Use: "clone <repo>",
Short: "Clone the given repo from GitHub",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
repo, ok := internal.ResolveAlias(args[0])
if !ok {
fmt.Fprintf(os.Stderr, "unknown repo: %s\n", args[0])
os.Exit(1)
}

var url string
if sshFlag {
url = internal.GithubBaseSSHURL + repo.RepoName + ".git"
} else {
url = internal.GithubBaseHTTPURL + repo.RepoName + ".git"
}

gitCmd := exec.Command("git", "clone", url)
gitCmd.Stdout = os.Stdout
gitCmd.Stderr = os.Stderr
if err := gitCmd.Run(); err != nil {
os.Exit(1)
}
},
}

func init() {
cloneCmd.Flags().BoolVar(&sshFlag, "ssh", false, "clone using SSH instead of HTTPS")
rootCmd.AddCommand(cloneCmd)
}
35 changes: 35 additions & 0 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var completionCmd = &cobra.Command{
Use: "completion",
Short: "Output shell alias/completion for the sce command",
Run: func(cmd *cobra.Command, args []string) {
fishVersion := os.Getenv("FISH_VERSION")
if fishVersion != "" {
exe, _ := os.Executable()
fmt.Println("# add this to your fish config")
fmt.Printf("function sce; %s $argv; end\n", exe)
return
}

shell := os.Getenv("SHELL")
exe, _ := os.Executable()
if shell != "" {
fmt.Println("# add this to your shell config")
fmt.Printf("alias sce=\"%s\"\n", exe)
} else {
fmt.Printf("# alias sce to: %s\n", exe)
}
},
}

func init() {
rootCmd.AddCommand(completionCmd)
}
Loading