Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12: rename project #13

Merged
merged 1 commit into from
Dec 17, 2023
Merged
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
2 changes: 1 addition & 1 deletion cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/gob/internal"
"github.com/kcmvp/gb/internal"
"github.com/samber/lo"
"github.com/spf13/cobra"
"io"
Expand Down
10 changes: 5 additions & 5 deletions cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/gob/cmd/plugin"
"github.com/kcmvp/gb/cmd/plugin"
"github.com/spf13/cobra"
)

Expand All @@ -16,17 +16,17 @@ var pluginCmd = &cobra.Command{
Short: "List all configured plugins",
Long: `List all configured plugins`,
RunE: func(cmd *cobra.Command, args []string) error {
// run 'gob plugin' will list all the configured plugins
// run 'gob plugin -u' will list all the configured plugins and install the uninstalled tools.
// run 'gb plugin' will list all the configured plugins
// run 'gb plugin -u' will list all the configured plugins and install the uninstalled tools.
return plugin.List(cmd)
},
}

// installPluginCmd represents the plugin install command
var installPluginCmd = &cobra.Command{
Use: "install",
Short: "Install a tool as gob plugin",
Long: `Install a tool as gob plugin`,
Short: "Install a tool as gb plugin",
Long: `Install a tool as gb plugin`,
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return fmt.Errorf(color.RedString(err.Error()))
Expand Down
10 changes: 5 additions & 5 deletions cmd/plugin/plugin_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
"github.com/fatih/color"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/kcmvp/gob/cmd/action"
"github.com/kcmvp/gob/internal"
"github.com/kcmvp/gb/cmd/action"
"github.com/kcmvp/gb/internal"
"github.com/samber/lo"
"github.com/spf13/cobra"
"os"
"path/filepath"
"strings"
)

// ToolAlias is the tool alias, for the convenience of run 'gob alias'
// ToolAlias is the tool alias, for the convenience of run 'gb alias'
var ToolAlias string

// ToolCommand is the tool command, it's the default command when run 'gob alias'
// ToolCommand is the tool command, it's the default command when run 'gb alias'
var ToolCommand string

// Install the specified tool as gob plugin
// Install the specified tool as gb plugin
var Install action.Execution = func(cmd *cobra.Command, args ...string) error {
if strings.HasSuffix(args[0], "@master") || strings.HasSuffix(args[0], "@latest") {
return fmt.Errorf("please use specific version instead of 'master' or 'latest'")
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"bytes"
"github.com/kcmvp/gob/internal"
"github.com/kcmvp/gb/internal"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"os"
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (
"context"
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/gob/cmd/action"
"github.com/kcmvp/gob/cmd/root"
"github.com/kcmvp/gob/internal"
"github.com/kcmvp/gb/cmd/action"
"github.com/kcmvp/gb/cmd/root"
"github.com/kcmvp/gb/internal"
"github.com/samber/lo"
"github.com/spf13/cobra"
"os"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gob",
Use: "gb",
Short: "Go project boot",
Long: `Supply most frequently used tool and best practices for go project development`,
ValidArgs: lo.Map(root.BuildActions(), func(item action.CmdAction, _ int) string {
Expand Down
4 changes: 2 additions & 2 deletions cmd/root/root_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bufio"
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/gob/cmd/action"
"github.com/kcmvp/gob/internal"
"github.com/kcmvp/gb/cmd/action"
"github.com/kcmvp/gb/internal"
"github.com/spf13/cobra"
"io/fs"
"os"
Expand Down
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"bytes"
"github.com/kcmvp/gob/internal"
"github.com/kcmvp/gb/internal"
"github.com/stretchr/testify/require"
"os"
"testing"
Expand Down
6 changes: 3 additions & 3 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
_ "embed"
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/gob/cmd/action"
"github.com/kcmvp/gob/cmd/setup"
"github.com/kcmvp/gb/cmd/action"
"github.com/kcmvp/gb/cmd/setup"
"github.com/samber/lo"
"github.com/spf13/cobra"
"strings"
Expand All @@ -16,7 +16,7 @@ var setupCmd = &cobra.Command{
Use: "setup",
Short: "Setup useful infrastructures and tools",
Long: `Setup useful infrastructures and tools
Run 'gob setup list get full supported list'`,
Run 'gb setup list get full supported list'`,
ValidArgs: func() []string {
return lo.Map(setup.Actions, func(item action.CmdAction, index int) string {
return item.A
Expand Down
File renamed without changes.
17 changes: 8 additions & 9 deletions cmd/setup/setup_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/go-git/go-git/v5"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/kcmvp/gob/cmd/action"
"github.com/kcmvp/gob/internal"
"github.com/kcmvp/gb/cmd/action"
"github.com/kcmvp/gb/internal"
"github.com/samber/lo"
"github.com/spf13/cobra"
"log"
Expand All @@ -21,7 +21,7 @@ import (
//go:embed setup.json
var data []byte

//go:embed commit_msg.tmpl
//go:embed commit_msg_hook.tmpl
var hook []byte

var setups []Setup
Expand Down Expand Up @@ -82,16 +82,15 @@ var gitHook action.Execution = func(cmd *cobra.Command, args ...string) error {
color.Yellow("Project is not in the source control, please add it to source repository")
return err
}
config := filepath.Join(internal.CurProject().Root(), "config")
os.Mkdir(config, os.ModePerm)
err := os.WriteFile(filepath.Join(config, "commit_msg.go"), hook, os.ModePerm)
script := filepath.Join(internal.CurProject().Root(), "commit_msg_hook.go")
err := os.WriteFile(script, hook, os.ModePerm)
if err != nil {
return err
}
hookMap := map[string]string{
"commit-msg": fmt.Sprintf("go run %s/config/commit_msg.go $1 $2", internal.CurProject().Root()),
"pre-commit": "gob lint test",
"pre-push": "gob lint test",
"commit-msg": fmt.Sprintf("go run %s $1 $2", filepath.Join(internal.CurProject().Root(), "commit_msg_hook.go")),
"pre-commit": "gb lint test",
"pre-push": "gb lint test",
}
shell := lo.IfF(internal.Windows(), func() string {
return "#!/usr/bin/env pwsh\n"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/kcmvp/gob
module github.com/kcmvp/gb

go 1.21.4

Expand Down
8 changes: 4 additions & 4 deletions internal/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ func (project *Project) LoadSettings() {
v := viper.New()
v.SetConfigType("yaml")
path := project.Root()
name := "gob"
name := "gb"
if testEnv {
name = fmt.Sprintf("gob-%s", lo.RandomString(12, lo.AlphanumericCharset))
name = fmt.Sprintf("gb-%s", lo.RandomString(12, lo.AlphanumericCharset))
path = project.Target()
}
v.AddConfigPath(path)
v.SetConfigName(name)
if err := v.ReadInConfig(); err != nil {
var configFileNotFoundError viper.ConfigFileNotFoundError
if errors.As(err, &configFileNotFoundError) {
color.Yellow("Warning: can not find configuration gob.yaml")
color.Yellow("Warning: can not find configuration gb.yaml")
}
}
project.cfg = fmt.Sprintf("%s.yaml", filepath.Join(path, name))
Expand Down Expand Up @@ -201,7 +201,7 @@ func (project *Project) PluginConfigured(url string) bool {
return ok
}

// InstallPlugin install the tool as gob plugin save it in gob.yml
// InstallPlugin install the tool as gb plugin save it in gb.yml
func (project *Project) InstallPlugin(url string, aliasAndCommand ...string) error {
base, name := NormalizePlugin(url)
gopath := os.Getenv("GOPATH")
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2023 kcheng.mvp@gmail.com
*/
package main

import "github.com/kcmvp/gob/cmd"
import "github.com/kcmvp/gb/cmd"

func main() {
cmd.Execute()
Expand Down