Skip to content

Commit

Permalink
docs: update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLYC committed Sep 13, 2023
1 parent 9b02db2 commit 6dbeea9
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 29 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For Chinese users, you can install the CMDR via a proxy:

```shell
curl -o- https://raw.githubusercontent.com/MrLYC/cmdr/master/install.sh | bash -s -p
```

### Manual
1. Download the latest release from [GitHub](https://github.com/mrlyc/cmdr/releases/latest);
Expand Down Expand Up @@ -45,8 +46,17 @@ Use a specified command version:
cmdr command use -n <command-name> -v <version>
```

## Upgrade
## Features

### Upgrade
To upgrade the CMDR, just run:
```shell
cmdr upgrade
```

### Url replacement
Speed up the download process by replacing the `url` to github proxy:
```shell
cmdr config set -k download.replace -v '{"match": "^https://raw.githubusercontent.com/.*$", "template": "https://ghproxy.com/{{ .location | urlquery }}"}'
cmdr command install -n install.sh -v 0.0.0 -l https://raw.githubusercontent.com/MrLYC/cmdr/master/install.sh
```
8 changes: 6 additions & 2 deletions cmd/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/mrlyc/cmdr/core"
"github.com/mrlyc/cmdr/core/utils"
Expand All @@ -16,9 +17,12 @@ var getCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cfg := core.GetConfiguration()
key := cfg.GetString(core.CfgKeyXConfigGetKey)
value := cfg.Get(key)
var dumps interface{}
utils.PanicOnError("unmarshal config failed", cfg.UnmarshalKey(key, &dumps))

fmt.Printf("key: %s, type: %T, value: %v\n", key, value, value)
out, err := yaml.Marshal(dumps)
utils.PanicOnError("marshal config failed", err)
fmt.Printf("%s", out)
},
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/mrlyc/cmdr/core"
"github.com/mrlyc/cmdr/core/utils"
Expand Down Expand Up @@ -32,7 +33,10 @@ var setCmd = &cobra.Command{
}

key := cfg.GetString(core.CfgKeyXConfigSetKey)
value := cfg.GetString(core.CfgKeyXConfigSetValue)
yamlValue := cfg.GetString(core.CfgKeyXConfigSetValue)

var value interface{}
utils.PanicOnError("mark yaml value", yaml.Unmarshal([]byte(yamlValue), &value))

userCfg.Set(key, value)

Expand Down
3 changes: 3 additions & 0 deletions core/manager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func (m *DownloadManager) search(name, output string) (string, error) {
func (m *DownloadManager) fetch(fetcher core.Fetcher, name, version, location, output string) (string, error) {
var err error
logger := core.GetLogger()
logger.Info("fetching", map[string]interface{}{
"uri": location,
})

for i := 0; i < m.retries; i++ {
err = fetcher.Fetch(name, version, location, output)
Expand Down
13 changes: 12 additions & 1 deletion core/utils/replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"regexp"
"text/template"

"github.com/mrlyc/cmdr/core"
)

type Replacement struct {
Expand All @@ -12,6 +14,8 @@ type Replacement struct {
}

func (r *Replacement) ReplaceString(s string) (string, bool) {
logger := core.GetLogger()

regexp := regexp.MustCompile(r.Match)
if !regexp.MatchString(s) {
return s, false
Expand All @@ -26,7 +30,14 @@ func (r *Replacement) ReplaceString(s string) (string, bool) {
return s, false
}

return buf.String(), true
replaced := buf.String()
logger.Debug("replaced", map[string]interface{}{
"location": s,
"match": r.Match,
"replaced": replaced,
})

return replaced, true
}

func NewReplacement(match, replacement string) *Replacement {
Expand Down
52 changes: 28 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/golang/mock v1.6.0
github.com/google/go-github/v39 v39.1.1-0.20211008144426-6b0f37fa430d
github.com/gookit/color v1.4.2
github.com/hashicorp/go-getter v1.7.1
github.com/hashicorp/go-getter v1.7.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.6.0
github.com/homedepot/flop v0.1.6
Expand All @@ -31,31 +31,32 @@ require (
)

require (
cloud.google.com/go v0.105.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go/iam v0.7.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
cloud.google.com/go v0.110.8 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.2 // indirect
cloud.google.com/go/storage v1.33.0 // indirect
github.com/PuerkitoBio/goquery v1.5.1 // indirect
github.com/andybalholm/cascadia v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/aws/aws-sdk-go v1.45.8 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -76,22 +77,25 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.103.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/api v0.140.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/grpc v1.58.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)
Loading

0 comments on commit 6dbeea9

Please sign in to comment.