Skip to content

Commit

Permalink
Big refactor and init testing (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhacaz authored Feb 27, 2024
1 parent f2bdf52 commit cf60cf9
Show file tree
Hide file tree
Showing 21 changed files with 822 additions and 475 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test

on:
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'

- name: Run tests
run: go test -json ./... > test.json

- name: Annotate tests
if: always()
uses: guyarb/golang-test-annotations@v0.5.1
with:
test-results: test.json
13 changes: 6 additions & 7 deletions cmd/add.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
)

// addCmd represents the add command
var addCmd = &cobra.Command{
Use: "add [branch]",
Short: "Add a branch to the current stack. If no branch is given, add the current branch.",
Long: `Add a branch to the current stack.`,
Args: cobra.RangeArgs(0, 1),
Long: `Add a branch to the current stack.`,
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
stack.Add("")
stack.Manager().AddBranch("")
} else {
stack.Add(args[0])
}
stack.Manager().AddBranch(args[0])
}
},
}

Expand Down
13 changes: 6 additions & 7 deletions cmd/checkout.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"strconv"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
"github.com/Bhacaz/gostacking/internal/stack"
"strconv"
)

// checkoutCmd represents the checkout command
Expand All @@ -16,10 +15,10 @@ var checkoutCmd = &cobra.Command{
Short: "Checkout a branch from a stack.",
Run: func(cmd *cobra.Command, args []string) {
if n, err := strconv.Atoi(args[0]); err == nil {
stack.CheckoutByNumber(n)
} else {
stack.CheckoutByName(args[0])
}
stack.Manager().CheckoutByNumber(n)
} else {
stack.Manager().CheckoutByName(args[0])
}
},
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/delete.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
)

// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete [stack]",
Short: "Delete a gostacking.",
Run: func(cmd *cobra.Command, args []string) {
stack.Delete(args[0])
stack.Manager().Delete(args[0])
},
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
)

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "List all stacks.",
Run: func(cmd *cobra.Command, args []string) {
stack.List()
stack.Manager().List()
},
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/new.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
// "fmt"
"github.com/spf13/cobra"
"github.com/Bhacaz/gostacking/internal/stack"
// "fmt"
"github.com/spf13/cobra"
)

// newCmd represents the new command
var newCmd = &cobra.Command{
Use: "new [name]",
Short: "Create a new gostacking.",
Long: `Create a a new gostacking by giving it a name.`,
Args: cobra.MinimumNArgs(1),
Long: `Create a a new gostacking by giving it a name.`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
stack.New(args[0])
stack.Manager().CreateStack(args[0])
},
}

Expand Down
13 changes: 6 additions & 7 deletions cmd/remove.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"strconv"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
"strconv"
)

var removeCmd = &cobra.Command{
Use: "remove",
Short: "Remove a branch from the current stack. (Branch name or number)",
Run: func(cmd *cobra.Command, args []string) {
if n, err := strconv.Atoi(args[0]); err == nil {
stack.RemoveByNumber(n)
} else {
stack.RemoveByName(args[0])
}
stack.Manager().RemoveByNumber(n)
} else {
stack.Manager().RemoveByName(args[0])
}
},
}

Expand Down
7 changes: 1 addition & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

Expand All @@ -10,8 +9,6 @@ import (
"github.com/spf13/cobra"
)



// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gostacking",
Expand Down Expand Up @@ -41,7 +38,5 @@ func init() {

// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}


7 changes: 3 additions & 4 deletions cmd/status.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"github.com/spf13/cobra"
"fmt"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
)

// statusCmd represents the status command
var statusCmd = &cobra.Command{
Use: "status",
Short: "Get current stack.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(stack.CurrentStackStatus())
fmt.Println(stack.Manager().CurrentStackStatus())
},
}

Expand Down
17 changes: 8 additions & 9 deletions cmd/switch.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"strconv"
"github.com/spf13/cobra"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
"strconv"
)

// switchCmd represents the switch command
var switchCmd = &cobra.Command{
Use: "switch [stack name or number]",
Short: "Change the current stack.",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if n, err := strconv.Atoi(args[0]); err == nil {
stack.SwitchByNumber(n)
} else {
stack.SwitchByName(args[0])
}
if n, err := strconv.Atoi(args[0]); err == nil {
stack.Manager().SwitchByNumber(n)
} else {
stack.Manager().SwitchByName(args[0])
}
},
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/sync.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/Bhacaz/gostacking/internal/stack"
"github.com/spf13/cobra"
)

// syncCmd represents the sync command
var syncCmd = &cobra.Command{
Use: "sync",
Short: "Merge all branch in a stack into the current branch.",
Run: func(cmd *cobra.Command, args []string) {
pushValue, _ := cmd.Flags().GetBool("push")
stack.Sync(pushValue)
pushValue, _ := cmd.Flags().GetBool("push")
stack.Manager().Sync(pushValue)
},
}

Expand Down
17 changes: 1 addition & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,9 @@ module github.com/Bhacaz/gostacking

go 1.21.5

require (
github.com/spf13/cobra v1.8.0
gopkg.in/src-d/go-git.v4 v4.13.1
)
require github.com/spf13/cobra v1.8.0

require (
github.com/emirpasic/gods v1.12.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/src-d/gcfg v1.4.0 // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading

0 comments on commit cf60cf9

Please sign in to comment.