Skip to content

Commit a55ac10

Browse files
Initial commit
0 parents  commit a55ac10

15 files changed

+531
-0
lines changed

Diff for: .github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily

Diff for: .github/release-drafter.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name-template: v$RESOLVED_VERSION
2+
tag-template: v$RESOLVED_VERSION
3+
template: |
4+
## What's Changed
5+
6+
$CHANGES

Diff for: .github/workflows/ci.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
on: push
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-20.04
7+
steps:
8+
- uses: actions/checkout@v3
9+
- uses: actions/setup-go@v2
10+
with:
11+
go-version: "1.18"
12+
- uses: actions/cache@v2
13+
with:
14+
path: |
15+
~/go
16+
~/.cache/go-build
17+
~/Library/Caches/go-build
18+
%LocalAppData%\go-build
19+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
20+
restore-keys: |
21+
${{ runner.os }}-go
22+
- uses: goreleaser/goreleaser-action@v2
23+
with:
24+
version: 1.7.0
25+
args: build --rm-dist --snapshot

Diff for: .github/workflows/release-drafter.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: release-drafter
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release-drafter:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: release-drafter/release-drafter@v5
12+
env:
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: .github/workflows/release.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: release
2+
on:
3+
release:
4+
types:
5+
- published
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-20.04
10+
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'dev-')
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-go@v2
14+
with:
15+
go-version: "1.18"
16+
- uses: actions/cache@v2
17+
with:
18+
path: |
19+
~/go
20+
~/.cache/go-build
21+
~/Library/Caches/go-build
22+
%LocalAppData%\go-build
23+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
24+
restore-keys: |
25+
${{ runner.os }}-go
26+
- name: Compute tag name
27+
id: tag-name
28+
run: echo "::set-output name=tag-name::${GITHUB_REF#refs/tags/}"
29+
- uses: goreleaser/goreleaser-action@v2
30+
with:
31+
version: 1.7.0
32+
args: release --parallelism 2
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
36+
GORELEASER_CURRENT_TAG: ${{ steps.tag-name.outputs.tag-name }}

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/run
2+
/dist

Diff for: .goreleaser.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
project_name: run
2+
3+
release:
4+
prerelease: auto
5+
6+
before:
7+
hooks:
8+
- go mod tidy
9+
10+
builds:
11+
- binary: bin/run
12+
env:
13+
- CGO_ENABLED=0
14+
ldflags:
15+
- -s -w
16+
id: macos
17+
goos: [darwin, linux, windows]
18+
19+
archives:
20+
- replacements:
21+
darwin: Darwin
22+
linux: Linux
23+
windows: Windows
24+
386: i386
25+
amd64: x86_64
26+
27+
changelog:
28+
skip: true
29+
30+
brews:
31+
- tap:
32+
owner: jacobwgillespie
33+
name: homebrew-tap
34+
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
35+
commit_author:
36+
name: Jacob Gillespie
37+
38+
homepage: https://github.com/jacobwgillespie/run
39+
description: Run is a tool for running package.json scripts
40+
license: MIT
41+
skip_upload: auto
42+
install: |
43+
bin.install "bin/run"
44+
bash_comp = Utils.safe_popen_read("#{bin}/run", "--completion", "bash")
45+
fish_comp = Utils.safe_popen_read("#{bin}/run", "--completion", "fish")
46+
zsh_comp = Utils.safe_popen_read("#{bin}/run", "--completion", "zsh")
47+
(bash_completion/"run").write bash_comp
48+
(fish_completion/"run.fish").write fish_comp
49+
(zsh_completion/"_run").write zsh_comp
50+
test: |
51+
system "#{bin}/run --help"

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Jacob Gillespie <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# run
2+
3+
A small utility for running `package.json` scripts and npm modules.
4+
5+
### Installation
6+
7+
```
8+
brew install jacobwgillespie/tap/run
9+
```
10+
11+
### Usage
12+
13+
```
14+
run [script] [flags]
15+
```
16+
17+
## License
18+
19+
MIT License, see `LICENSE`.

Diff for: completion.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func completion(shell string) error {
9+
switch shell {
10+
case "bash":
11+
return runCmd.GenBashCompletion(os.Stdout)
12+
case "zsh":
13+
return runCmd.GenZshCompletion(os.Stdout)
14+
case "fish":
15+
return runCmd.GenFishCompletion(os.Stdout, true)
16+
case "powershell":
17+
return runCmd.GenPowerShellCompletionWithDesc(os.Stdout)
18+
case "unknown":
19+
return runCmd.Help()
20+
default:
21+
return fmt.Errorf("unknown shell: %s", shell)
22+
}
23+
}

Diff for: go.mod

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module github.com/jacobwgillespie/run
2+
3+
go 1.18
4+
5+
require (
6+
github.com/charmbracelet/lipgloss v0.5.0
7+
github.com/spf13/cobra v1.4.0
8+
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb
9+
)
10+
11+
require (
12+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
13+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
14+
github.com/mattn/go-isatty v0.0.14 // indirect
15+
github.com/mattn/go-runewidth v0.0.13 // indirect
16+
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 // indirect
17+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
18+
github.com/rivo/uniseg v0.2.0 // indirect
19+
github.com/spf13/pflag v1.0.5 // indirect
20+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
21+
)

Diff for: go.sum

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
2+
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
4+
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
5+
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
6+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
7+
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
8+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
9+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
10+
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
11+
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
12+
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
13+
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=
14+
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
15+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 h1:STjmj0uFfRryL9fzRA/OupNppeAID6QJYPMavTL7jtY=
16+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
17+
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
18+
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
19+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
20+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
21+
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
22+
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
23+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
24+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
25+
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb h1:pC9Okm6BVmxEw76PUu0XUbOTQ92JX11hfvqTjAV3qxM=
26+
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
27+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
28+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
29+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
31+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

Diff for: main.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
10+
if err := runMain(); err != nil {
11+
fmt.Println(err)
12+
os.Exit(1)
13+
}
14+
15+
}
16+
17+
var scriptName string
18+
var scriptArgs []string
19+
20+
func runMain() error {
21+
displayHelp := false
22+
23+
Loop:
24+
for idx, arg := range os.Args {
25+
if idx == 0 {
26+
continue
27+
}
28+
29+
switch {
30+
case arg == "--help" || arg == "-h":
31+
displayHelp = true
32+
continue
33+
34+
case arg == "--completion":
35+
shell := "unknown"
36+
if len(os.Args) > idx+1 {
37+
shell = os.Args[idx+1]
38+
}
39+
return completion(shell)
40+
41+
case arg[0] != '-':
42+
scriptName = arg
43+
scriptArgs = os.Args[idx+1:]
44+
os.Args = os.Args[:idx+1]
45+
break Loop
46+
47+
default:
48+
return fmt.Errorf("unknown flag: %s", arg)
49+
}
50+
}
51+
52+
if displayHelp || len(os.Args) == 1 {
53+
return runCmd.Help()
54+
}
55+
56+
return runCmd.Execute()
57+
}

0 commit comments

Comments
 (0)