Skip to content

Commit

Permalink
Add 'yj'
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Dec 29, 2021
1 parent 4a231ff commit fcc720e
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $ staticd <tool>
- `k9s`: [derailed/k9s][k9s], Kubernetes CLI to manage your clusters in style.
- `upx`: [upx/upx][upx], the Ultimate Packer for eXecutables.
- `xh`: [ducaale/xh][xh], friendly and fast tool for sending HTTP requests.
- `yj`: [sclevine/yj][yj], convert between YAML, TOML, JSON, and HCL.

[bat]: https://github.com/sharkdp/bat
[btm]: https://github.com/ClementTsang/bottom
Expand All @@ -26,3 +27,4 @@ $ staticd <tool>
[k9s]: https://github.com/derailed/k9s
[upx]: https://github.com/upx/upx
[xh]: https://github.com/ducaale/xh
[yj]: https://github.com/sclevine/yj
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ func main() {
},
}

yjCmd := &cobra.Command{
Use: tools.Yj,
Short: "Convert between YAML, TOML, JSON, and HCL",
Run: func(cmd *cobra.Command, args []string) {
run(tools.Yj)
},
}

versionCmd := &cobra.Command{
Use: "version",
Short: "Show version",
Expand All @@ -148,6 +156,7 @@ func main() {
rootCmd.AddCommand(k9sCmd)
rootCmd.AddCommand(upxCmd)
rootCmd.AddCommand(xhCmd)
rootCmd.AddCommand(yjCmd)
rootCmd.AddCommand(versionCmd)

err := rootCmd.Execute()
Expand Down
10 changes: 10 additions & 0 deletions tables/arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ var Arch = map[string]map[string]map[string]string{
"arm": "arm",
},
},
Yj: {
"darwin": {
"amd64": "",
},
"linux": {
"amd64": "",
"arm": "arm-v7",
"arm64": "arm64",
},
},
}
10 changes: 10 additions & 0 deletions tables/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ var OS = map[string]map[string]map[string]string{
"arm": "unknown-linux-gnueabihf",
},
},
Yj: {
"darwin": {
"amd64": "macos",
},
"linux": {
"amd64": "linux",
"arm": "linux",
"arm64": "linux",
},
},
}
1 change: 1 addition & 0 deletions tables/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ const (
K9s = "k9s"
UPX = "upx"
Xh = "xh"
Yj = "yj"
)
1 change: 1 addition & 0 deletions tables/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ var URL = map[string]string{
K9s: "https://github.com/derailed/k9s/releases",
UPX: "https://github.com/upx/upx/releases",
Xh: "https://github.com/ducaale/xh/releases",
Yj: "https://github.com/sclevine/yj/releases",
}
9 changes: 9 additions & 0 deletions tools/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ func (t *Tool) AssetXh() {
t.Asset.Name = baseName + ".tar.gz"
t.Asset.WithinArchive = path.Join(baseName, t.Name)
}

func (t *Tool) AssetYj() {
t.Asset.IsBinary = true
t.Asset.Name = fmt.Sprintf("yj-%v", t.OS)

if t.Arch != "" {
t.Asset.Name += fmt.Sprintf("-%v", t.Arch)
}
}
33 changes: 33 additions & 0 deletions tools/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func (s *AssetTestSuite) TestDestination() {
},
dest: "/usr/local/bin/xh",
},
{
tool: &Tool{
Name: Yj,
},
dest: "/usr/local/bin/yj",
},
}

for _, tt := range table {
Expand Down Expand Up @@ -148,6 +154,15 @@ func (s *AssetTestSuite) TestIsBinary() {
os: "linux",
binary: false,
},
{
tool: &Tool{
Name: Yj,
Version: "v5.0.0",
},
arch: "amd64",
os: "linux",
binary: true,
},
}

for _, tt := range table {
Expand Down Expand Up @@ -227,6 +242,24 @@ func (s *AssetTestSuite) TestName() {
os: "linux",
name: "xh-v0.14.0-x86_64-unknown-linux-musl.tar.gz",
},
{
tool: &Tool{
Name: Yj,
Version: "v5.0.0",
},
arch: "amd64",
os: "linux",
name: "yj-linux",
},
{
tool: &Tool{
Name: Yj,
Version: "v5.0.0",
},
arch: "arm",
os: "linux",
name: "yj-linux-arm-v7",
},
}

for _, tt := range table {
Expand Down
10 changes: 7 additions & 3 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
K9s = "k9s"
UPX = "upx"
Xh = "xh"
Yj = "yj"
)

type Asset struct {
Expand Down Expand Up @@ -145,6 +146,8 @@ func (t *Tool) SetAsset() error {
t.AssetUPX()
case Xh:
t.AssetXh()
case Yj:
t.AssetYj()
}

if t.Asset.Name == "" {
Expand All @@ -155,10 +158,11 @@ func (t *Tool) SetAsset() error {
}

func (t *Tool) SetRuntime(arch string, os string) error {
t.Arch = tables.Arch[t.Name][os][arch]
t.OS = tables.OS[t.Name][os][arch]
var archOk, osOk bool
t.Arch, archOk = tables.Arch[t.Name][os][arch]
t.OS, osOk = tables.OS[t.Name][os][arch]

if t.Arch == "" || t.OS == "" {
if !archOk || !osOk {
return fmt.Errorf("no candidate for %v on %v/%v", t.Name, os, arch)
}

Expand Down

0 comments on commit fcc720e

Please sign in to comment.