Skip to content

Commit

Permalink
Merge pull request #19 from foomo/feature/add-flag-sets
Browse files Browse the repository at this point in the history
Add flag sets
  • Loading branch information
franklinkim authored Apr 7, 2023
2 parents db05bf2 + 5f097a9 commit 0b37b90
Show file tree
Hide file tree
Showing 35 changed files with 860 additions and 522 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- uses: golangci/golangci-lint-action@v3
Expand All @@ -27,8 +27,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- run: go test -v ./...
- run: make test
- run: make test.demo

2 changes: 1 addition & 1 deletion .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
cache: true
go-version-file: go.mod
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ linters:
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
- testableexamples # linter checks if examples are testable (have an expected output) [fast: true, auto-fix: false]
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
#- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
#- unparam # Reports unused function parameters [fast: false, auto-fix: false]
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ outdated:
test:
@go test -v ./...

.PHONY: test.demo
## Run tests
test.demo: install
@rm -rf tmp/test
@mkdir -p tmp/test
@cd tmp/test && \
git init . && \
git remote add origin https://github.com/foomo/posh-test-demo && \
posh init && \
make shell.build && \
bin/posh execute welcome demo

.PHONY: lint
## Run linter
lint:
Expand All @@ -45,6 +57,7 @@ lint.super:

.PHONY: install
## Run go install
install: GOPATH=${shell go env GOPATH}
install:
@go install -a main.go
@mv "${GOPATH}/bin/main" "${GOPATH}/bin/posh"
Expand Down
4 changes: 3 additions & 1 deletion cmd/prompt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

intconfig "github.com/foomo/posh/internal/config"
"github.com/foomo/posh/pkg/config"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -30,6 +32,6 @@ var promptCmd = &cobra.Command{
return err
}

return plg.Prompt(cmd.Context(), cfg)
return plg.Prompt(context.TODO(), cfg)
},
}
3 changes: 2 additions & 1 deletion embed/scaffold/init/$.makerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
## Override log level (error|warn|info|debug|trace)
# level=debug
# POSH_PATH=.posh
# POSH_LEVEL=debug
19 changes: 7 additions & 12 deletions embed/scaffold/init/$.posh/pkg/plugin.go.gotext
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,15 @@ func New(l log.Logger) (plugin.Plugin, error) {
}

// add commands
inst.commands.Add(
command.NewExit(l),
command.NewHelp(l, inst.commands),
)
inst.commands.Add(command.NewExit(l))
inst.commands.Add(command.NewHelp(l, inst.commands))

// Welcome
if cmd, err := pkgcommand.NewWelcome(l,
pkgcommand.WelcomeWithConfigKey("welcome"),
); err != nil {
return nil, err
} else {
inst.commands.Add(cmd)
}

inst.commands.MustAdd(
pkgcommand.NewWelcome(l,
pkgcommand.WelcomeWithConfigKey("welcome"),
),
)

return inst, nil
}
Expand Down
31 changes: 20 additions & 11 deletions embed/scaffold/init/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

# --- Config -----------------------------------------------------------------

level?=info
POSH_PATH?=.posh
POSH_LEVEL?=info

# --- Helpers -----------------------------------------------------------------



.PHONY: bin/posh
# Builds posh and takes the git hash to detect changes
bin/posh: current=$(shell bin/posh version)
bin/posh: version=$(shell git ls-files -s .posh/pkg | git hash-object --stdin)
bin/posh: current=$(shell test -f bin/posh && bin/posh version || echo '')
bin/posh: version=$(shell git ls-files -s .posh | git hash-object --stdin)
bin/posh: commitHash=$(shell git rev-parse HEAD)
bin/posh: buildTimestamp=$(shell date +%s)
bin/posh: ldflags=\
Expand All @@ -18,7 +22,8 @@ bin/posh: ldflags=\
-X github.com/foomo/posh/internal/version.BuildTimestamp=${buildTimestamp}
bin/posh:
@if [ "${current}" != "${version}" ]; then \
cd .posh && go mod tidy && go build -trimpath -ldflags="${ldflags}" -o ../bin/posh main.go; \
echo "rebuilding shell ('${current}' != '${version}')" && \
cd ${POSH_PATH} && go mod tidy && go build -trimpath -ldflags="${ldflags}" -o "../bin/posh" main.go; \
fi

# --- Targets -----------------------------------------------------------------
Expand All @@ -31,26 +36,30 @@ clean:
.PHONY: config
## Print posh config
config: bin/posh
@bin/posh config --level ${level}
@bin/posh config --level ${POSH_LEVEL}

.PHONY: brew
## Install project specific packages
brew: bin/posh
@bin/posh brew --level ${level}
@bin/posh brew --level ${POSH_LEVEL}

.PHONY: require
## Validate dependencies
require: bin/posh
@bin/posh require --level ${level}
@bin/posh require --level ${POSH_LEVEL}

.PHONY: shell
## Start the interactive
## Start the interactive project shell
shell: require brew
@bin/posh prompt --level ${level}
@bin/posh prompt --level ${POSH_LEVEL}

.PHONY: shell.build
## Build the interactive project shell
shell.build: clean bin/posh

.PHONY: shell.rebuild
## Rebuild and start the interactive
shell.rebuild: clean shell
## Build and start the interactive project shell
shell.rebuild: shell.build shell

## === Utils ===

Expand Down
32 changes: 16 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ require (
github.com/c-bata/go-prompt v0.2.6
github.com/charlievieth/fastwalk v1.0.1
github.com/foomo/fender v0.4.4
github.com/go-git/go-git/v5 v5.5.2
github.com/go-git/go-git/v5 v5.6.1
github.com/gofrs/flock v0.8.1
github.com/pkg/errors v0.9.1
github.com/pterm/pterm v0.12.54
github.com/samber/lo v1.37.0
github.com/pterm/pterm v0.12.57
github.com/samber/lo v1.38.1
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
github.com/whilp/git-urls v1.0.0
)

Expand All @@ -26,16 +26,16 @@ require (
atomicgo.dev/keyboard v0.2.9 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.1.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.0 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
Expand All @@ -58,10 +58,10 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pjbgf/sha1cd v0.2.3 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
Expand All @@ -70,13 +70,13 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.6.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.8.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 0b37b90

Please sign in to comment.