Skip to content

Commit b246f86

Browse files
authored
Merge pull request #24 from b4b4r07/fix/inconsistency
Fix inconsistency parts and remove bad implementations coming from old package
2 parents efe7664 + 844fa6a commit b246f86

File tree

5 files changed

+103
-123
lines changed

5 files changed

+103
-123
lines changed

docs/configuration/command.md

+84-84
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,11 @@ afx's goal is to finally support to install packages as `command`, `plugin` or b
44

55
## Parameters
66

7-
### build.steps
8-
9-
Type | Required
10-
---|---
11-
list | yes (when using `build`)
12-
13-
`build.steps` can be specified build commands to build a package.
14-
15-
=== "Case 1"
16-
17-
```yaml hl_lines="7 8 9 10" title="Using sudo"
18-
github:
19-
- name: jhawthorn/fzy
20-
description: A better fuzzy finder
21-
owner: jhawthorn
22-
repo: fzy
23-
command:
24-
build:
25-
steps:
26-
- make
27-
- sudo make install
28-
```
29-
30-
In this case, build steps has `sudo` command but it can be run as expected. But in advance you will be asked to input sudo password.
31-
32-
=== "Case 2"
33-
34-
```yaml hl_lines="7 8 9" title="Using go build"
35-
github:
36-
- name: iovisor/kubectl-trace
37-
description: Schedule bpftrace programs on your kubernetes cluster using the kubectl
38-
owner: iovisor
39-
repo: kubectl-trace
40-
command:
41-
build:
42-
steps:
43-
- go build -o kubectl-trace cmd/kubectl-trace/root.go
44-
link:
45-
- from: kubectl-trace
46-
to: kubectl-trace
47-
```
48-
49-
In this case, build steps run `go build` command because this package does not provide GitHub releases on its own page. So we need to build by ourselves. afx build feature is very helpful in such a case.
50-
51-
`go build` command creates `red` command to current working directory so you need to have `link` section to install the built binary to your PATH.
52-
53-
### build.env
54-
55-
Type | Required
56-
---|---
57-
map | no
58-
59-
`build.env` can be specified environemnt variables used when running build a package.
60-
61-
=== "Case 1"
62-
63-
```yaml hl_lines="11 12"
64-
github:
65-
- name: jhawthorn/fzy
66-
description: A better fuzzy finder
67-
owner: jhawthorn
68-
repo: fzy
69-
command:
70-
build:
71-
steps:
72-
- make
73-
- sudo make install
74-
env:
75-
VERSION: 1.0
76-
```
77-
78-
In this case, VERSION is specified to change version used in build steps.
79-
807
### link.from
818

82-
Type | Required
9+
Type | Default
8310
---|---
84-
string | yes (when using `link`)
11+
string | (required)
8512

8613
`link.from` can be specified where to install from.
8714

@@ -121,11 +48,11 @@ string | yes (when using `link`)
12148

12249
### link.to
12350

124-
Type | Required
51+
Type | Default
12552
---|---
126-
string | no
53+
string | `$AFX_COMMAND_PATH/(command-name)`
12754

128-
`link.to` can be specified where to install to.
55+
`link.to` can be specified where to install to. If omitted, the command will be installed to `$AFX_COMMAND_PATH`.
12956

13057
=== "Case 1"
13158

@@ -183,9 +110,9 @@ string | no
183110

184111
### env
185112

186-
Type | Required
113+
Type | Default
187114
---|---
188-
map | no
115+
map | `{}`
189116

190117
`env` allows you to set environment variables. By having this section in same YAML file of package declaration, you can manage it with same file. When we don't have afx, we should have environment variables in shell config (e.g. zshrc) even if not installed it yet or failed to install it. But thanks to afx, afx users can keep it with same files and enable it only while a package is installed.
191118

@@ -221,9 +148,9 @@ map | no
221148

222149
### alias
223150

224-
Type | Required
151+
Type | Default
225152
---|---
226-
map | no
153+
map | `{}`
227154

228155
`alias` allows you to set command aliases.
229156

@@ -288,11 +215,84 @@ map | no
288215
- from: '**/bat'
289216
```
290217

218+
### build.steps
219+
220+
Type | Default
221+
---|---
222+
list | `[]`
223+
224+
`build.steps` can be specified build commands to build a package.
225+
226+
=== "Case 1"
227+
228+
```yaml hl_lines="7 8 9 10" title="Using sudo"
229+
github:
230+
- name: jhawthorn/fzy
231+
description: A better fuzzy finder
232+
owner: jhawthorn
233+
repo: fzy
234+
command:
235+
build:
236+
steps:
237+
- make
238+
- sudo make install
239+
```
240+
241+
In this case, build steps has `sudo` command but it can be run as expected. But in advance you will be asked to input sudo password.
242+
243+
=== "Case 2"
244+
245+
```yaml hl_lines="7 8 9" title="Using go build"
246+
github:
247+
- name: iovisor/kubectl-trace
248+
description: Schedule bpftrace programs on your kubernetes cluster using the kubectl
249+
owner: iovisor
250+
repo: kubectl-trace
251+
command:
252+
build:
253+
steps:
254+
- go build -o kubectl-trace cmd/kubectl-trace/root.go
255+
link:
256+
- from: kubectl-trace
257+
to: kubectl-trace
258+
```
259+
260+
In this case, build steps run `go build` command because this package does not provide GitHub releases on its own page. So we need to build by ourselves. afx build feature is very helpful in such a case.
261+
262+
`go build` command creates `red` command to current working directory so you need to have `link` section to install the built binary to your PATH.
263+
264+
### build.env
265+
266+
Type | Required
267+
---|---
268+
map | `{}`
269+
270+
`build.env` can be specified environemnt variables used when running build a package.
271+
272+
=== "Case 1"
273+
274+
```yaml hl_lines="11 12"
275+
github:
276+
- name: jhawthorn/fzy
277+
description: A better fuzzy finder
278+
owner: jhawthorn
279+
repo: fzy
280+
command:
281+
build:
282+
steps:
283+
- make
284+
- sudo make install
285+
env:
286+
VERSION: 1.0
287+
```
288+
289+
In this case, VERSION is specified to change version used in build steps.
290+
291291
### snippet
292292

293293
Type | Required
294294
---|---
295-
string | no
295+
string | `""`
296296

297297
`snippet` allows you to specify the command which are runned when starting new shell.
298298

@@ -318,7 +318,7 @@ string | no
318318

319319
Type | Required
320320
---|---
321-
string | no
321+
string | `""`
322322

323323
`if` allows you to specify the condition to load packages. If it returns true, then the command will be linked. But if it returns false, the command will not be linked.
324324

docs/configuration/plugin.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ afx's goal is to finally support to install packages as `command`, `plugin` or b
66

77
### sources
88

9-
Type | Required
9+
Type | Default
1010
---|---
11-
list | yes
11+
list | (required)
1212

1313
`sources` allows you to select what to load files when starting shell.
1414

@@ -56,9 +56,9 @@ list | yes
5656

5757
### env
5858

59-
Type | Required
59+
Type | Default
6060
---|---
61-
list | no
61+
map | `{}`
6262

6363
`env` allows you to set environment variables. By having this section in same YAML file of package declaration, you can manage it with same file. When we don't have afx, we should have environment variables in shell config (e.g. zshrc) even if not installed it yet or failed to install it. But thanks to afx, afx users can keep it with same files and enable it only while a package is installed.
6464

@@ -88,9 +88,9 @@ list | no
8888

8989
### snippet
9090

91-
Type | Required
91+
Type | Default
9292
---|---
93-
string | no
93+
string | `""`
9494

9595
`snippet` allows you to specify the command which are runned when starting new shell.
9696

@@ -114,9 +114,9 @@ string | no
114114

115115
### snippet-prepare (beta)
116116

117-
Type | Required
117+
Type | Default
118118
---|---
119-
string | no
119+
string | `""`
120120

121121
`snippet-prepare` allows you to specify the command which are runned when starting new shell. Unlike `snippet`, this `snippet-prepare` is run before `source` command.
122122

@@ -147,9 +147,9 @@ This option comes from https://github.com/b4b4r07/afx/issues/6.
147147

148148
### if
149149

150-
Type | Required
150+
Type | Default
151151
---|---
152-
string | no
152+
string | `""`
153153

154154
`if` allows you to specify the condition to load packages. If it returns true, then the plugin will be loaded. But if it returns false, the plugin will not be loaded.
155155

pkg/config/command.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// Command is
2121
type Command struct {
2222
Build *Build `yaml:"build"`
23-
Link []*Link `yaml:"link"` // validate:"required"
23+
Link []*Link `yaml:"link" validate:"required"`
2424
Env map[string]string `yaml:"env"`
2525
Alias map[string]string `yaml:"alias"`
2626
Snippet string `yaml:"snippet"`
@@ -107,20 +107,21 @@ func (c Command) GetLink(pkg Package) ([]Link, error) {
107107
if err != nil {
108108
return links, errors.Wrapf(err, "%s: failed to get links", pkg.GetName())
109109
}
110+
111+
log.Printf("[DEBUG] Run file globbing: %s", file)
110112
var src string
111113
switch len(matches) {
112114
case 0:
113-
log.Printf("[ERROR] %s: no matches\n", file)
114-
continue
115+
return links, fmt.Errorf("%s: %q no matches", pkg.GetName(), link.From)
115116
case 1:
116117
// OK pattern: matches should be only one
117118
src = matches[0]
118119
case 2:
119120
// TODO: Update this with more flexiblities
120-
msg := fmt.Sprintf("[ERROR] %s: %d files matched: %#v\n", pkg.GetName(), len(matches), matches)
121-
return links, errors.New(msg)
121+
return links, fmt.Errorf("%s: %d files matched: %#v\n", pkg.GetName(), len(matches), matches)
122122
default:
123-
return links, errors.New("unknown error occured")
123+
log.Printf("[ERROR] matched files: %#v", matches)
124+
return links, errors.New("too many files are matched in file glob")
124125
}
125126
links = append(links, Link{
126127
From: src,

pkg/config/config.go

-21
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,8 @@ func parse(cfg Config) []Package {
7979
var pkgs []Package
8080

8181
for _, pkg := range cfg.GitHub {
82-
// TODO: Remove?
83-
if pkg.HasReleaseBlock() {
84-
msg := fmt.Sprintf(
85-
"[DEBUG] %s: added '**/%s' to link.from to complete missing links in github release",
86-
pkg.GetName(), pkg.Release.Name,
87-
)
88-
defaultLinks := []*Link{
89-
{From: filepath.Join("**", pkg.Release.Name)},
90-
}
91-
if pkg.HasCommandBlock() {
92-
links, _ := pkg.Command.GetLink(pkg)
93-
if len(links) == 0 {
94-
log.Printf(msg)
95-
pkg.Command.Link = defaultLinks
96-
}
97-
} else {
98-
log.Printf(msg)
99-
pkg.Command = &Command{Link: defaultLinks}
100-
}
101-
}
10282
pkgs = append(pkgs, pkg)
10383
}
104-
10584
for _, pkg := range cfg.Gist {
10685
pkgs = append(pkgs, pkg)
10786
}

pkg/config/github.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type GitHub struct {
4040
Release *Release `yaml:"release"`
4141

4242
Plugin *Plugin `yaml:"plugin"`
43-
Command *Command `yaml:"command"` // validate:"required_with=Release"
43+
Command *Command `yaml:"command" validate:"required_with=Release"` // TODO: (not required Release)
4444

4545
DependsOn []string `yaml:"depends-on"`
4646
}
@@ -602,7 +602,7 @@ func (r *GitHubRelease) Unarchive(asset Asset) error {
602602
return errors.Wrapf(err, "%s: failed to unarchive", r.Name)
603603
}
604604

605-
log.Printf("[DEBUG] removed archive file: %s\n", asset.Path)
605+
log.Printf("[DEBUG] removed archive file: %s", asset.Path)
606606
os.Remove(asset.Path)
607607

608608
return nil

0 commit comments

Comments
 (0)