Add sync command
This commit is contained in:
commit
5e6a5e23fd
18 changed files with 1077 additions and 0 deletions
54
config/cmd.go
Normal file
54
config/cmd.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/akamensky/argparse"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultConfigPath = ".config/grm/config.yaml"
|
||||
)
|
||||
|
||||
func getDefaultConfigDir() string {
|
||||
// Only systems like Unix, Linux, and Windows systems are supported
|
||||
userHomeDir, _ := os.UserHomeDir()
|
||||
return fmt.Sprintf("%v/%v", userHomeDir, defaultConfigPath)
|
||||
}
|
||||
|
||||
func ParseCliArguments(name, description string, arguments []string) (CliArguments, error) {
|
||||
|
||||
parser := argparse.NewParser(name, description)
|
||||
|
||||
syncCMD := parser.NewCommand("sync", "Synchronize repositories with remote branches, if the repository does not exist, clone it. (If pulling is not possible, the repository will be fetched)")
|
||||
|
||||
configFile := parser.String("c", "config-file", &argparse.Options{
|
||||
Default: getDefaultConfigDir(),
|
||||
Help: "Path to the configuration file",
|
||||
})
|
||||
|
||||
version := parser.Flag("v", "version", &argparse.Options{
|
||||
Default: false,
|
||||
Help: "Print version",
|
||||
})
|
||||
|
||||
color := parser.Flag("", "no-color", &argparse.Options{
|
||||
Default: false,
|
||||
Help: "Turn off color printing",
|
||||
})
|
||||
if err := parser.Parse(arguments); err != nil {
|
||||
return CliArguments{}, err
|
||||
}
|
||||
if !syncCMD.Happened() && !(*version) {
|
||||
return CliArguments{}, errors.New(errNoCommand)
|
||||
}
|
||||
|
||||
return CliArguments{
|
||||
ConfigurationFile: *configFile,
|
||||
Sync: syncCMD.Happened(),
|
||||
Version: *version,
|
||||
Color: !(*color),
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue