Skip to content

Commit

Permalink
fix: changes + gofumpt and golangci + cli install issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DOOduneye committed Apr 28, 2024
1 parent 519b759 commit 663d498
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 136 deletions.
16 changes: 16 additions & 0 deletions cli/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
linters:
enable:
- exportloopref
- gocritic
- gosec
- ineffassign
- misspell
- prealloc
- unconvert
- unparam
- goimports
- whitespace

linters-settings:
whitespace:
multi-func: true
Empty file removed cli/LICENSE
Empty file.
6 changes: 3 additions & 3 deletions cli/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

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

func init() {
Expand Down Expand Up @@ -78,4 +78,4 @@ var dbInsertCmd = &cobra.Command{
os.Exit(1)
}
},
}
}
66 changes: 47 additions & 19 deletions cli/cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import (
)

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

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

formatFrontendCmd.AddCommand(formatWebCmd)
formatFrontendCmd.AddCommand(formatMobileCmd)
Expand All @@ -27,16 +28,16 @@ func init() {
}

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

var formatWebCmd = &cobra.Command{
Use: "web",
Use: "web",
Aliases: []string{"w"},
Short: "Frontend web formatting commands",
Args: cobra.NoArgs,
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 {
Expand All @@ -47,10 +48,10 @@ var formatWebCmd = &cobra.Command{
}

var formatMobileCmd = &cobra.Command{
Use: "mobile",
Use: "mobile",
Aliases: []string{"m"},
Short: "Frontend mobile formatting commands",
Args: cobra.NoArgs,
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 {
Expand All @@ -61,10 +62,10 @@ var formatMobileCmd = &cobra.Command{
}

var formatDashboardCmd = &cobra.Command{
Use: "dashboard",
Use: "dashboard",
Aliases: []string{"d"},
Short: "Frontend dashboard formatting commands",
Args: cobra.NoArgs,
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 {
Expand All @@ -75,10 +76,10 @@ var formatDashboardCmd = &cobra.Command{
}

var formatLibCmd = &cobra.Command{
Use: "lib",
Use: "lib",
Aliases: []string{"l"},
Short: "Frontend lib formatting commands",
Args: cobra.NoArgs,
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 {
Expand All @@ -89,12 +90,39 @@ var formatLibCmd = &cobra.Command{
}

var formatBackendCmd = &cobra.Command{
Use: "backend",
Short: "Backend formatting commands",
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 := helpers.Execute(exec.Command("go", "fmt", "./..."), helpers.BACKEND_DIR)
_, 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)
Expand Down
105 changes: 50 additions & 55 deletions cli/cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,36 @@ import (
)

var lintCmd = &cobra.Command{
Use: "lint",
Use: "lint",
Aliases: []string{"l"},
Short: "Linting commands",
Short: "Linting commands",
}

func init() {
rootCmd.AddCommand(lintCmd)
lintCmd.AddCommand(lintFrontendCmd)
lintCmd.AddCommand(lintBackendCmd)
lintCmd.AddCommand(lintCliCmd)

lintFrontendCmd.AddCommand(lintWebCmd)
lintFrontendCmd.AddCommand(lintMobileCmd)
lintFrontendCmd.AddCommand(lintDashboardCmd)
lintFrontendCmd.AddCommand(lintLibCmd)

lintWebCmd.Flags().BoolP("fix", "f", false, "Fix linting errors")
lintMobileCmd.Flags().BoolP("fix", "f", false, "Fix linting errors")
lintDashboardCmd.Flags().BoolP("fix", "f", false, "Fix linting errors")
}

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

var lintWebCmd = &cobra.Command{
Use: "web",
Short: "Frontend web linting commands",
Use: "web",
Short: "Lints the frontend web",
Aliases: []string{"w"},
Args: cobra.NoArgs,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fix, _ := cmd.Flags().GetBool("fix")

var command string
if fix {
command = " --fix"
}

err := helpers.Execute(exec.Command("yarn", "run", "lint"+command), helpers.WEB_DIR)
err := helpers.Execute(exec.Command("yarn", "run", "lint", "--fix"), helpers.WEB_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -58,19 +48,12 @@ var lintWebCmd = &cobra.Command{
}

var lintMobileCmd = &cobra.Command{
Use: "mobile",
Short: "Frontend mobile linting commands",
Use: "mobile",
Short: "Lints the frontend mobile",
Aliases: []string{"m"},
Args: cobra.NoArgs,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fix, _ := cmd.Flags().GetBool("fix")

var command string
if fix {
command = " --fix"
}

err := helpers.Execute(exec.Command("yarn", "run", "lint"+command), helpers.MOBILE_DIR)
err := helpers.Execute(exec.Command("yarn", "run", "lint", "--fix"), helpers.MOBILE_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -79,19 +62,12 @@ var lintMobileCmd = &cobra.Command{
}

var lintDashboardCmd = &cobra.Command{
Use: "dashboard",
Short: "Frontend dashboard linting commands",
Use: "dashboard",
Short: "Lints the frontend dashboard",
Aliases: []string{"d"},
Args: cobra.NoArgs,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fix, _ := cmd.Flags().GetBool("fix")

var command string
if fix {
command = " --fix"
}

err := helpers.Execute(exec.Command("yarn", "run", "lint"+command), helpers.DASHBOARD_DIR)
err := helpers.Execute(exec.Command("yarn", "run", "lint", "--fix"), helpers.DASHBOARD_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -100,34 +76,53 @@ var lintDashboardCmd = &cobra.Command{
}

var lintLibCmd = &cobra.Command{
Use: "lib",
Short: "Frontend lib linting commands",
Use: "lib",
Short: "Lints the lib directory",
Aliases: []string{"l"},
Args: cobra.NoArgs,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fix, _ := cmd.Flags().GetBool("fix")
err := helpers.Execute(exec.Command("yarn", "run", "lint", "--fix"), helpers.LIB_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var command string
if fix {
command = " --fix"
var lintBackendCmd = &cobra.Command{
Use: "backend",
Short: "Lints the backend",
Aliases: []string{"be"},
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
_, err := exec.LookPath("golangci-lint")
if err != nil {
fmt.Println("golangci-lint is not installed. Please install it by running the following command:")
fmt.Println("curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2")
os.Exit(1)
}

err := helpers.Execute(exec.Command("yarn", "run", "lint"+command), helpers.LIB_DIR)
err = helpers.Execute(exec.Command("golangci-lint", "run", "--fix"), helpers.BACKEND_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

var lintBackendCmd = &cobra.Command{
Use: "backend",
Short: "Backend linting commands",
Aliases: []string{"be"},
var lintCliCmd = &cobra.Command{
Use: "cli",
Short: "Lints the CLI",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
// TODO: golangci-lint
err := helpers.Execute(exec.Command("go", "lint", "./..."), helpers.BACKEND_DIR)
_, err := exec.LookPath("golangci-lint")
if err != nil {
fmt.Println("golangci-lint is not installed. Please install it by running the following command:")
fmt.Println("curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2")
os.Exit(1)
}

err = helpers.Execute(exec.Command("golangci-lint", "run", "--fix"), helpers.CLI_DIR)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var rootCmd = &cobra.Command{
Use: "sac",
Short: "SAC manages the GenerateNU Student Activity Calendar platform",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
return cmd.Help()
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -25,4 +25,4 @@ func Execute() {
if err != nil {
os.Exit(1)
}
}
}
Loading

0 comments on commit 663d498

Please sign in to comment.