Skip to content

Commit

Permalink
Merge pull request #58 from b4b4r07/babarot/gh-extension
Browse files Browse the repository at this point in the history
Support gh extension
  • Loading branch information
b4b4r07 authored Mar 19, 2023
2 parents 7f61977 + 614a7b6 commit 8947559
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Full document is here: [AFX](https://babarot.me/afx/)

- Allows to manage various packages types:
- GitHub / GitHub Release / Gist / HTTP (web) / Local
- [gh extensions](https://github.com/topics/gh-extension)
- Manages as CLI commands, shell plugins or both
- Easy to install/update/uninstall
- Easy to configure with YAML
Expand Down
30 changes: 30 additions & 0 deletions docs/configuration/package/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ number | `0` (all commits)

Limit fetching to the specified number of commits from the tip of each remote branch history. If fetching to a shallow repository, specify 1 or more number, deepen or shorten the history to the specified number of commits.

### as

Key | Type | Default
---|---|---
gh-extension | Object | `null`

Change the installation behavior of the packages based on specified package type. In current afx, all packages are based on where it's hosted e.g. `github`. Almost all cases are not problem on that but some package types (such as "brew" or "gh extension") will be able to do more easily if there is a dedicated parameters to install the packages. In this `as` section, it expands more this installation method. Some of package types (especially "brew") will be coming soon in near future.

=== "gh-extension"

Install a package as [gh extension](https://github.blog/2023-01-13-new-github-cli-extension-tools/). Officially gh extensions can be installed with `gh extension install owern/repo` command ([guide](https://cli.github.com/manual/gh_extension_install)) but it's difficult to manage what we downloaded as code. In afx, by handling them as the same as other packages, it allows us to codenize them.

Key | Type | Default
---|---|---
name | string | (required)
tag | string | `latest`
rename-to | string | `""`

```yaml
- name: yusukebe/gh-markdown-preview
description: GitHub CLI extension to preview Markdown looks like GitHub.
owner: yusukebe
repo: gh-markdown-preview
as:
gh-extension:
name: gh-markdown-preview
tag: v1.4.0
rename-to: gh-md # markdown-preview is long so rename it to shorten.
```

### release.name

Type | Default
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ Flags:

Use "afx [command] --help" for more information about a command.
```

![](https://user-images.githubusercontent.com/4442708/224565945-2c09b729-82b7-4829-9cbc-e247b401b689.gif)
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
golang.org/x/sync v0.1.0
golang.org/x/term v0.6.0
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.2.2
)

require (
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
11 changes: 8 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/b4b4r07/afx/pkg/dependency"
"github.com/b4b4r07/afx/pkg/errors"
"github.com/b4b4r07/afx/pkg/state"
"github.com/go-playground/validator/v10"
"github.com/goccy/go-yaml"
Expand Down Expand Up @@ -55,6 +54,7 @@ func Read(path string) (Config, error) {
defer f.Close()

validate := validator.New()
validate.RegisterValidation("gh-extension", ValidateGHExtension)
d := yaml.NewDecoder(
bufio.NewReader(f),
yaml.DisallowUnknownField(),
Expand Down Expand Up @@ -98,7 +98,7 @@ func (c Config) Parse() ([]Package, error) {
func visitYAML(files *[]string) filepath.WalkFunc {
return func(path string, info os.FileInfo, err error) error {
if err != nil {
return errors.Wrapf(err, "%s: failed to visit", path)
return fmt.Errorf("%w: %s: failed to visit", err, path)
}
switch filepath.Ext(path) {
case ".yaml", ".yml":
Expand Down Expand Up @@ -178,7 +178,7 @@ func Sort(given []Package) ([]Package, error) {

resolved, err := dependency.Resolve(graph)
if err != nil {
return pkgs, errors.Wrap(err, "failed to resolve dependency graph")
return pkgs, fmt.Errorf("%w: failed to resolve dependency graph", err)
}

for _, node := range resolved {
Expand Down Expand Up @@ -245,6 +245,11 @@ func getResource(pkg Package) state.Resource {
if pkg.HasReleaseBlock() {
id = fmt.Sprintf("github.com/release/%s/%s", pkg.Owner, pkg.Repo)
}
if pkg.IsGHExtension() {
ty = "GitHub (gh extension)"
gh := pkg.As.GHExtension
paths = append(paths, gh.GetHome())
}
case Gist:
ty = "Gist"
id = fmt.Sprintf("gist.github.com/%s/%s", pkg.Owner, pkg.ID)
Expand Down
Loading

0 comments on commit 8947559

Please sign in to comment.