Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Sidorin committed Jun 29, 2022
1 parent 2a371f1 commit 737d503
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,32 @@ Require go 1.16.0 or later, to install run:
`-s` - soft launch

`--no-color` - disable colored output

## Rewrite Aliases
You can export env `GOST_ALIASES` to rewrite build-in aliases
and export `GOST_ADD_ALIASES` to add and replace build-in aliases. For example: `GOST_ALIASES="/home/user/gost.aliases.yaml" ./gost mod -s webserver`

You can rewrite default aliases and bundles of aliases with your own - gost try to read
file `gost.aliases.yaml` in a current directory to rewrite build-in aliases.

Also two flags present:

`--aliases` - file to full rewrite build-in aliases (include loaded from `gost.aliases.yaml`)

`--aliases-add` - file to add and replace build-in aliases

Reading and replacing order:
1. From env
2. From file in current directory
3. From flags

## Multi-threads (experimental)
You can run `ghost mod` with` --threads = N` for multithreading, but then the order in which
the `go get` is executed is not guaranteed, there may be side effects.

## Supported commands
### mod
Do `go get -u` commands with use of aliases and bundles of aliases.
Do `go get -u` commands with use of aliases and bundles of aliases.

Usage: `gost mod module1 module2 ...`

Expand Down Expand Up @@ -61,17 +84,6 @@ Use soft Launch
/usr/local/go/bin/go get -u gopkg.in/Graylog2/go-gelf.v1
/usr/local/go/bin/go mod download
```
However, you can rewrite default aliases and bundles of aliases with your own - gost try to read
file `gost.aliases.yaml` in a current directory to rewrite build-in aliases. Also two flags present:

`--aliases` - file to full rewrite build-in aliases (include loaded from `gost.aliases.yaml`)

`--aliases-add` - file to add and replace build-in aliases

Or you can export env `GOST_ALIASES` to rewrite build-in aliases (equivalent to `--aliases`)

You can run `ghost mod` with` --threads = N` for multithreading, but then the order in which
the `go get` is executed is not guaranteed, there may be side effects.

### start
Starts new project in dir `--package-name` in current dir, do `mod init` and all, what do `gost mod` command.
35 changes: 32 additions & 3 deletions app/ModAliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
)

const defaultFileName = "gost.aliases.yaml"
const envAliasesName = "GOST_ALIASES"
const envAliasesAddName = "GOST_ADD_ALIASES"

//go:embed gost.aliases.yaml
var defAliases []byte
Expand Down Expand Up @@ -50,9 +52,10 @@ type ModAliases struct {
}

func init() {
loadAliasesFromEnv()
f, err := os.ReadFile(defaultFileName)
if err == nil {
fmt.Println("Load aliases from " + defaultFileName)
fmt.Println("Rewrite aliases from " + defaultFileName)
defAliases = f
}
ma, err := getAliasesByBytes(defAliases)
Expand All @@ -66,6 +69,32 @@ func init() {
fmt.Println("[ERROR]: " + err.Error())
os.Exit(1)
}
loadAddAliasesFromEnv()
}

func loadAliasesFromEnv() {
if fn, ok := os.LookupEnv(envAliasesName); ok {
f, err := os.ReadFile(fn)
if err == nil {
fmt.Println("Rewrite aliases by env " + envAliasesName + " from file " + fn)
defAliases = f
}
}
}

func loadAddAliasesFromEnv() {
if fn, ok := os.LookupEnv(envAliasesAddName); ok {
ma, err := getAliasesByFile(fn, false)
if err != nil {
return
}
newMa, err := defModAliases.Glue(ma)
if err != nil {
return
}
defModAliases = newMa
fmt.Println("Add aliases from env " + envAliasesAddName + " from file " + fn)
}
}

func getAliasesByBytes(str []byte) (ModAliases, error) {
Expand All @@ -79,7 +108,7 @@ func GetAliases() ModAliases {
return defModAliases
}

//GetDefaultAliasesH - return string of default aliases and bundles set for description of commands
//GetDefaultAliasesHelp - return string of default aliases and bundles set for description of commands
func GetDefaultAliasesHelp() string {
return string(defAliases)
}
Expand Down Expand Up @@ -111,7 +140,7 @@ func LoadAliasesFromFlags(outIo, errIo io.Writer, aliasesFile, addAliasesFile st
return false
}
defModAliases = ma
_, _ = outIo.Write([]byte("Load aliases from " + aliasesFile))
_, _ = outIo.Write([]byte("Load aliases from " + aliasesFile + "\n"))
}
if addAliasesFile != "" {
ma, err := getAliasesByFile(addAliasesFile, false)
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

const (
Version = "v1.2.0"
//no color flag name
NoColor = "no-color"
//verbose flag full name
Expand All @@ -27,7 +28,7 @@ var cfg *envviper.EnvViper
var rootCmd = &cobra.Command{
Use: "gost",
Short: "Go Start project - helper for start go projects",
Long: "Go Start (gost) - utility for help you to start go project without type some `go get ...` commands." +
Long: "Go Start (gost) " + Version + " - utility for help you to start go project without type some `go get ...` commands." +
"\nCommand has some aliases for popular and useful go modules, and has some aliases for bundles of modules",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if cfg.GetBool("no-color") {
Expand Down Expand Up @@ -58,7 +59,6 @@ func init() {
// initConfig reads in config file and ENV variables if set.
func initConfig() {
cfg = envviper.NewEnvViper()
cfg.SetEnvParamsSimple("GOST")
_ = cfg.BindPFlag("v", rootCmd.PersistentFlags().Lookup(Verbose))
_ = cfg.BindPFlag("s", rootCmd.PersistentFlags().Lookup(SoftLaunch))
_ = cfg.BindPFlag(NoColor, rootCmd.PersistentFlags().Lookup(NoColor))
Expand Down

0 comments on commit 737d503

Please sign in to comment.