6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 19:44:41 +00:00
Files
git-get/cmd/list/main.go
Grzegorz Dlugoszewski 8c132cdafa Remove gogit and major refactoring (#2)
* Fix typo in readme

* Reimplement all git methods without go-git

* Rename repo pkg to git, add gitconfig methods

* Improve tests for configuration reading

* Rename package file to io and move RepoFinder there

* Refactor printers

- Remove smart printer
- Decouple printers from git repos with interfaces
- Update printer functions
- Remove unnecessary flags
- Add better remote URL detection

* Update readme and go.mod

* Add author to git commit in tests

Otherwise tests will fail in CI.

* Install git before running tests and don't use cgo

* Add better error message, revert installing git

* Ensure commit message is in quotes

* Set up git config before running tests
2020-06-24 23:54:44 +02:00

51 lines
1.6 KiB
Go

package main
import (
"fmt"
"git-get/pkg"
"git-get/pkg/cfg"
"git-get/pkg/git"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var cmd = &cobra.Command{
Use: "git list",
Short: "List all repositories cloned by 'git get' and their status.",
RunE: run,
Args: cobra.NoArgs,
Version: cfg.Version(),
SilenceUsage: true, // We don't want to show usage on legit errors (eg, wrong path, repo already existing etc.)
}
func init() {
cmd.PersistentFlags().BoolP(cfg.KeyFetch, "f", false, "First fetch from remotes before listing repositories.")
cmd.PersistentFlags().StringP(cfg.KeyOutput, "o", cfg.DefOutput, fmt.Sprintf("Output format. Allowed values: [%s].", strings.Join(cfg.AllowedOut, ", ")))
cmd.PersistentFlags().StringP(cfg.KeyReposRoot, "r", "", "Path to repos root where repositories are cloned. (default \"~/repositories\")")
cmd.PersistentFlags().BoolP("help", "h", false, "Print this help and exit.")
cmd.PersistentFlags().BoolP("version", "v", false, "Print version and exit.")
viper.BindPFlag(cfg.KeyFetch, cmd.PersistentFlags().Lookup(cfg.KeyFetch))
viper.BindPFlag(cfg.KeyOutput, cmd.PersistentFlags().Lookup(cfg.KeyOutput))
viper.BindPFlag(cfg.KeyReposRoot, cmd.PersistentFlags().Lookup(cfg.KeyReposRoot))
}
func run(cmd *cobra.Command, args []string) error {
cfg.Init(&git.ConfigGlobal{})
config := &pkg.ListCfg{
Fetch: viper.GetBool(cfg.KeyFetch),
Output: viper.GetString(cfg.KeyOutput),
Root: viper.GetString(cfg.KeyReposRoot),
}
return pkg.List(config)
}
func main() {
cmd.Execute()
}