-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add remove command and update README.md
- Added a new `remove` command to remove repositories from `gee.toml` configuration. - Ensure `remove` command can detect the repository name from the current directory if `.git` is present, or use `--repo` flag to specify the repository name. - Updated command interface to take `cli.Context` parameter. - Updated all commands to pass `cli.Context` to their respective Run functions. - Enhanced README.md: - Detailed usage instructions for all commands including the new `remove` command. - Clarified the requirement for `gee add` to be run inside a `.git` directory. - Highlighted search behavior for `gee.toml` in current and parent directories.
- Loading branch information
1 parent
cbd5442
commit c9a11cc
Showing
11 changed files
with
201 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"gee/pkg/command" | ||
"gee/pkg/types" | ||
"gee/pkg/util" | ||
"github.com/urfave/cli/v2" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type RemoveCommand struct { | ||
Git command.GitRepoOperation | ||
RepoUtils *util.RepoUtils | ||
} | ||
|
||
func NewRemoveCommand() *RemoveCommand { | ||
repoOp := command.GitRepoOperation{} | ||
return &RemoveCommand{ | ||
Git: repoOp, | ||
RepoUtils: util.NewRepoUtils(repoOp), | ||
} | ||
} | ||
|
||
func RemoveCmd() *cli.Command { | ||
removeCmd := NewRemoveCommand() | ||
return &cli.Command{ | ||
Name: "remove", | ||
Usage: "remove repo in gee.toml", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "repo", | ||
Aliases: []string{"r"}, | ||
Usage: "specify the repository name to remove", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
return removeCmd.Run(c) | ||
}, | ||
} | ||
} | ||
|
||
func (cmd *RemoveCommand) Run(c *cli.Context) error { | ||
var err error | ||
repoName := c.String("repo") | ||
if repoName == "" { | ||
repoName, err = cmd.getRepoNameFromGitDir() | ||
if err != nil { | ||
return err | ||
} | ||
if repoName == "" { | ||
return util.NewWarning("please specify the repository name to remove") | ||
} | ||
} | ||
|
||
// Load the configuration | ||
geeCtx, err := cmd.LoadConfiguration() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
repoPath := "" | ||
for _, repo := range geeCtx.Repos { | ||
if repo.Name == repoName { | ||
repoPath = repo.Path | ||
break | ||
} | ||
} | ||
if repoPath == "" { | ||
return util.NewWarning(fmt.Sprintf("repository %s not found in the configuration", repoName)) | ||
} | ||
|
||
// update configuration | ||
newRepos := []types.Repo{} | ||
for _, repo := range geeCtx.Repos { | ||
if repo.Name != repoName { | ||
newRepos = append(newRepos, repo) | ||
} | ||
} | ||
|
||
geeCtx.Repos = newRepos | ||
configHelper := util.NewConfigHelper() | ||
|
||
err = configHelper.SaveConfig(geeCtx.ConfigFilePath, geeCtx) | ||
if err != nil { | ||
return util.NewWarning(err.Error()) | ||
} | ||
return util.NewInfo(fmt.Sprintf("repository %s successfully remove", repoName)) | ||
} | ||
|
||
func (cmd *RemoveCommand) GetWorkingDirectory() (string, error) { | ||
return os.Getwd() | ||
} | ||
|
||
func (cmd *RemoveCommand) LoadConfiguration() (*types.GeeContext, error) { | ||
cwd, err := cmd.GetWorkingDirectory() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return util.NewConfigHelper().LoadConfig(cwd) | ||
} | ||
|
||
// Get repository name from .git directory | ||
func (cmd *RemoveCommand) getRepoNameFromGitDir() (string, error) { | ||
cwd, err := cmd.GetWorkingDirectory() | ||
if err != nil { | ||
return "", util.NewWarning(err.Error()) | ||
} | ||
gitDir := filepath.Join(cwd, ".git") | ||
exists, err := cmd.RepoUtils.FileExists(gitDir) | ||
if err != nil { | ||
return "", fmt.Errorf("error checking .git directory: %v", err) | ||
} | ||
if !exists { | ||
return "", nil | ||
} | ||
return filepath.Base(cwd), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ func main() { | |
cmd.PullCmd(), | ||
cmd.StatusCmd(), | ||
cmd.CloneCmd(), | ||
cmd.RemoveCmd(), | ||
} | ||
|
||
// Run the CLI app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package command | ||
|
||
import "gee/pkg/types" | ||
import ( | ||
"gee/pkg/types" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type Command interface { | ||
Run() error | ||
Run(c *cli.Context) error | ||
GetWorkingDirectory(string, error) | ||
LoadConfiguration(types.GeeContext, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters