Skip to content

Commit d87fa34

Browse files
committed
initial commit
0 parents  commit d87fa34

19 files changed

+1117
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

Gopkg.lock

Lines changed: 154 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
name = "github.com/fatih/color"
30+
version = "1.7.0"
31+
32+
[[constraint]]
33+
name = "github.com/ghodss/yaml"
34+
version = "1.0.0"
35+
36+
[[constraint]]
37+
name = "github.com/onsi/ginkgo"
38+
version = "1.5.0"
39+
40+
[[constraint]]
41+
name = "github.com/onsi/gomega"
42+
version = "1.4.0"
43+
44+
[[constraint]]
45+
name = "github.com/pkg/errors"
46+
version = "0.8.0"
47+
48+
[[constraint]]
49+
name = "github.com/spf13/cobra"
50+
version = "0.0.3"
51+
52+
[[constraint]]
53+
name = "gopkg.in/yaml.v2"
54+
version = "2.2.1"
55+
56+
[prune]
57+
go-tests = true
58+
unused-packages = true

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# ReSc (Remote Script) - The easy way to share scripts
2+
3+
`resc` is a CLI tool that executes remote bash scripts located on Github.
4+
5+
## Install
6+
7+
### OS X
8+
9+
```
10+
$ wget -O /usr/local/bin/resc https://github.com/JulzDiverse/resc/releases/download/v0.1.0/resc-darwin-amd64 && chmod +x /usr/local/bin/resc
11+
```
12+
13+
OR
14+
15+
**Homebrew**
16+
17+
```
18+
$ brew tap julzdiverse/tools
19+
$ brew install resc
20+
```
21+
22+
### Linux
23+
24+
```
25+
$ wget -O /usr/bin/resc https://github.com/JulzDiverse/resc/releases/download/v0.1.0/resc-linux-amd64 && chmod +x /usr/bin/resc
26+
```
27+
28+
## Hello, World!
29+
30+
You can use `resc` to run `resc` scripts located in any Github repository. For example, let's run a `Hello, World!` script:
31+
32+
```bash
33+
$ resc run hello-world --repo JulzDiverse/remote-scripts
34+
```
35+
36+
This runs the `hello-world` script located in the `JulzDiverse/remote-scripts` repository.
37+
38+
## `resc` scripts
39+
40+
`resc` scripts requires one or more top level directories inside a GitHub repository that contain a `run.sh` script and a `README.md` file. In case of the `hello-world` script the directory looks like this:
41+
42+
```
43+
.remote-scripts
44+
└── hello-world
45+
   ├── run.sh
46+
   └── README.md
47+
```
48+
49+
- The `directory name` (here `hello-world`) indicates the script
50+
- The `run.sh` is the bash script that is run by `resc`
51+
- The `README.md` is a Markdown file that provides information for a script (eg description, usage). The `README.md` is processed by the `resc` CLI and should only contain the following markdown syntax:
52+
- H1 (#)
53+
- H2 (##)
54+
- Bold (\*\*text\*\*)
55+
- Italic (\_text\_)
56+
57+
## Usage
58+
59+
### Run `resc` scripts (`run`)
60+
61+
Running a `resc` script is nothing more than:
62+
63+
```
64+
$ resc run <script-name> --repo <github-user|github-org>/<github-repo>
65+
```
66+
67+
or if you have set a repository, it's even simpler:
68+
69+
```
70+
$ resc run <script-name>
71+
```
72+
73+
You can also provide parameters to a script using `--args|-a` option. Try it:
74+
75+
```
76+
$ resc run hello-world -r JulzDiverse/remote-scripts -a your-name
77+
```
78+
79+
### Set base `resc` script repository (`set`)
80+
81+
You can set a base `resc` script repository, s.t you are not required to specify the repository of a script everytime you execute the `resc run`.
82+
83+
```
84+
$ resc set <github-user|github-org>/<github-repo>
85+
```
86+
87+
### Get some script info (`man`)
88+
89+
If you want to know what a script does before you run it, you can check the provided README by calling `man`:
90+
91+
```
92+
$ resc man <script-name>
93+
```
94+
95+
### Print a script (`man`)
96+
97+
If you want to see what a script exactly does or you want to save it to your local machine, you can use the `print` command:
98+
99+
```
100+
$ resc print <script-name>
101+
```
102+
103+
to save a script, pipe it to a file:
104+
105+
```
106+
$ resc print <script-name> > script.sh
107+
```
108+
109+
## Development
110+
111+
```
112+
$ go get github.com/JulzDiverse/resc (or git clone repository)
113+
$ dep ensure
114+
```

cmd/resc/cmd/man.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cmd
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/JulzDiverse/resc/processor"
9+
"github.com/JulzDiverse/resc/scriptmanager"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var manCmd = &cobra.Command{
14+
Use: "man",
15+
Short: "prints the description of the script",
16+
Run: man,
17+
}
18+
19+
func man(cmd *cobra.Command, args []string) {
20+
userRepo, err := cmd.Flags().GetString("repo")
21+
exitWithError(err)
22+
23+
var user, repo string
24+
if userRepo == "" {
25+
user, repo = configFromFile()
26+
} else {
27+
sl := strings.Split(userRepo, "/")
28+
user = sl[0]
29+
repo = sl[1]
30+
}
31+
32+
scriptManager := scriptmanager.New(
33+
"https://raw.githubusercontent.com",
34+
user,
35+
repo,
36+
)
37+
38+
readme, err := scriptManager.GetReadmeForScript(args[0])
39+
exitWithError(err)
40+
41+
scanner := bufio.NewScanner(strings.NewReader(string(readme)))
42+
processor := processor.New()
43+
for scanner.Scan() {
44+
line := processor.Process(scanner.Text())
45+
fmt.Println(line)
46+
}
47+
}
48+
49+
func initMan() {
50+
manCmd.Flags().StringP("repo", "r", "", "name of the repository containing the script. Pattern: <user|org>/<repo>")
51+
}

0 commit comments

Comments
 (0)