diff --git a/README.md b/README.md index 4c722c2..af73726 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ $ staticd - `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 @@ -26,3 +27,4 @@ $ staticd [k9s]: https://github.com/derailed/k9s [upx]: https://github.com/upx/upx [xh]: https://github.com/ducaale/xh +[yj]: https://github.com/sclevine/yj diff --git a/main.go b/main.go index ddb8837..b650bcc 100644 --- a/main.go +++ b/main.go @@ -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", @@ -148,6 +156,7 @@ func main() { rootCmd.AddCommand(k9sCmd) rootCmd.AddCommand(upxCmd) rootCmd.AddCommand(xhCmd) + rootCmd.AddCommand(yjCmd) rootCmd.AddCommand(versionCmd) err := rootCmd.Execute() diff --git a/tables/arch.go b/tables/arch.go index d0bb44c..94b51df 100644 --- a/tables/arch.go +++ b/tables/arch.go @@ -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", + }, + }, } diff --git a/tables/os.go b/tables/os.go index 45e9215..155ccd6 100644 --- a/tables/os.go +++ b/tables/os.go @@ -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", + }, + }, } diff --git a/tables/tools.go b/tables/tools.go index 875fc83..50d6489 100644 --- a/tables/tools.go +++ b/tables/tools.go @@ -8,4 +8,5 @@ const ( K9s = "k9s" UPX = "upx" Xh = "xh" + Yj = "yj" ) diff --git a/tables/url.go b/tables/url.go index 2bd28f0..6363d55 100644 --- a/tables/url.go +++ b/tables/url.go @@ -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", } diff --git a/tools/asset.go b/tools/asset.go index 460a1c8..86946e0 100644 --- a/tools/asset.go +++ b/tools/asset.go @@ -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) + } +} diff --git a/tools/asset_test.go b/tools/asset_test.go index c9aff89..61a04ad 100644 --- a/tools/asset_test.go +++ b/tools/asset_test.go @@ -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 { @@ -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 { @@ -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 { diff --git a/tools/tools.go b/tools/tools.go index 3ff4ccf..911858d 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -21,6 +21,7 @@ const ( K9s = "k9s" UPX = "upx" Xh = "xh" + Yj = "yj" ) type Asset struct { @@ -145,6 +146,8 @@ func (t *Tool) SetAsset() error { t.AssetUPX() case Xh: t.AssetXh() + case Yj: + t.AssetYj() } if t.Asset.Name == "" { @@ -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) }