diff --git a/.gitignore b/.gitignore index 32f64cf69..ae8fc4ac0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ mc /arkade-* /faas-cli* test.out -docker-compose.yaml \ No newline at end of file +docker-compose.yaml* \ No newline at end of file diff --git a/README.md b/README.md index 72d3c851f..38687609a 100644 --- a/README.md +++ b/README.md @@ -239,23 +239,26 @@ arkade system install containerd \ --systemd ``` -Run the following to see what's available `arkade system install`: - -``` - actions-runner Install GitHub Actions Runner - buildkitd Install Buildkitd - caddy Install Caddy Server - cni Install CNI plugins - containerd Install containerd - firecracker Install Firecracker - gitlab-runner Install GitLab Runner - go Install Go - node Install Node.js - prometheus Install Prometheus - pwsh Install Powershell - registry Install registry - tc-redirect-tap Install tc-redirect-tap -``` +### Catalog of System Installs: + +| SYSTEM INSTALL | DESCRIPTION | +|-----------------|-------------------------------| +| actions-runner | Install GitHub Actions Runner | +| buildkitd | Install Buildkitd | +| caddy | Install Caddy Server | +| cni | Install CNI plugins | +| containerd | Install containerd | +| firecracker | Install Firecracker | +| gitlab-runner | Install GitLab Runner | +| go | Install Go | +| node | Install Node.js | +| prometheus | Install Prometheus | +| pwsh | Install Powershell | +| registry | Install registry | +| tc-redirect-tap | Install tc-redirect-tap | + There are 13 system installations available. + + The initial set of system apps is now complete, learn more in the original proposal: [Feature: system packages for Linux servers, CI and workstations #654](https://github.com/alexellis/arkade/issues/654) @@ -694,8 +697,8 @@ An app is software or an add-on for your Kubernetes cluster. A CLI or "tool" is a command line tool that you run directly on your own workstation or a CI runner. ### Catalog of Apps - -| TOOL | DESCRIPTION | + +| APP | DESCRIPTION | |-------------------------|---------------------------------------------------------------------| | argocd | Install argocd | | cassandra | Install cassandra | @@ -749,13 +752,13 @@ A CLI or "tool" is a command line tool that you run directly on your own worksta | traefik2 | Install traefik2 | | vault | Install vault | | waypoint | Install Waypoint | + There are 52 apps that you can install on your cluster. -There are 52 apps that you can install on your cluster. - + > Note to contributors, run `go build && ./arkade install --print-table` to generate this list ### Catalog of CLIs - + | TOOL | DESCRIPTION | |------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [actions-usage](https://github.com/self-actuated/actions-usage) | Get usage insights from GitHub Actions. | @@ -922,4 +925,5 @@ There are 52 apps that you can install on your cluster. | [yt-dlp](https://github.com/yt-dlp/yt-dlp) | Fork of youtube-dl with additional features and fixes | There are 162 tools, use `arkade get NAME` to download one. + > Note to contributors, run `go build && ./arkade get --format markdown` to generate this list \ No newline at end of file diff --git a/cmd/get.go b/cmd/get.go index 7d4b23b0a..d68ce0916 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -74,17 +74,17 @@ and provides a fast and easy alternative to a package manager.`, if len(format) > 0 { if get.TableFormat(format) == get.MarkdownStyle { - get.CreateToolsTable(tools, get.MarkdownStyle) + fmt.Print(get.CreateToolsTable(tools, get.MarkdownStyle)) } else if get.TableFormat(format) == get.ListStyle { for _, r := range tools { fmt.Printf("%s\n", r.Name) } } else { - get.CreateToolsTable(tools, get.TableStyle) + fmt.Print(get.CreateToolsTable(tools, get.TableStyle)) } } else { - get.CreateToolsTable(tools, get.TableStyle) + fmt.Print(get.CreateToolsTable(tools, get.TableStyle)) } return nil } diff --git a/cmd/install.go b/cmd/install.go index f4075be8d..c466ff408 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -5,8 +5,8 @@ package cmd import ( "fmt" - "os" "sort" + "strings" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" @@ -46,27 +46,7 @@ command.`, printTable, _ := command.Flags().GetBool("print-table") if printTable { - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Tool", "Description"}) - - table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) - table.SetCenterSeparator("|") - table.SetAutoWrapText(false) - - appSortedList := make([]string, 0, len(appList)) - - for a := range appList { - appSortedList = append(appSortedList, a) - } - sort.Strings(appSortedList) - - for _, k := range appSortedList { - table.Append([]string{k, appList[k].Installer().Short}) - } - - table.Render() - - fmt.Printf("\nThere are %d apps that you can install on your cluster.\n", len(appList)) + fmt.Print(CreateAppsTable(appList)) return nil } @@ -181,3 +161,31 @@ func NewArkadeApp(cmd func() *cobra.Command, msg string) ArkadeApp { InfoMessage: msg, } } + +func CreateAppsTable(apps map[string]ArkadeApp) string { + + tableString := &strings.Builder{} + table := tablewriter.NewWriter(tableString) + table.SetHeader([]string{"App", "Description"}) + table.SetCaption(true, + fmt.Sprintf("\nThere are %d apps that you can install on your cluster.\n", len(apps))) + + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) + table.SetCenterSeparator("|") + table.SetAutoWrapText(false) + + appSortedList := make([]string, 0, len(apps)) + + for a := range apps { + appSortedList = append(appSortedList, a) + } + sort.Strings(appSortedList) + + for _, k := range appSortedList { + table.Append([]string{k, apps[k].Installer().Short}) + } + + table.Render() + + return tableString.String() +} diff --git a/cmd/system/install.go b/cmd/system/install.go index ac6f8b0d2..116f54d8e 100644 --- a/cmd/system/install.go +++ b/cmd/system/install.go @@ -3,7 +3,14 @@ package system -import "github.com/spf13/cobra" +import ( + "fmt" + "sort" + "strings" + + "github.com/olekukonko/tablewriter" + "github.com/spf13/cobra" +) func MakeInstall() *cobra.Command { @@ -37,3 +44,33 @@ func MakeInstall() *cobra.Command { return command } + +func CreateSystemTable(sys []*cobra.Command) string { + + tableString := &strings.Builder{} + table := tablewriter.NewWriter(tableString) + table.SetHeader([]string{"System Install", "Description"}) + table.SetCaption(true, + fmt.Sprintf("\nThere are %d system installations available.\n", len(sys))) + + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) + table.SetCenterSeparator("|") + table.SetAutoWrapText(false) + + var sysMap = make(map[string]string, len(sys)) + sortedList := make([]string, 0, len(sys)) + + for _, s := range sys { + sysMap[s.Use] = s.Short + sortedList = append(sortedList, s.Use) + } + sort.Strings(sortedList) + + for _, sysInst := range sortedList { + table.Append([]string{sysInst, sysMap[sysInst]}) + } + + table.Render() + + return tableString.String() +} diff --git a/cmd/update/readme.go b/cmd/update/readme.go new file mode 100644 index 000000000..d639a6c1d --- /dev/null +++ b/cmd/update/readme.go @@ -0,0 +1,86 @@ +// Copyright (c) arkade author(s) 2022. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +package update + +import ( + "fmt" + "os" + "sort" + "strings" + + install "github.com/alexellis/arkade/cmd" + system "github.com/alexellis/arkade/cmd/system" + "github.com/alexellis/arkade/pkg/get" + "github.com/spf13/cobra" +) + +func MakeReadme() *cobra.Command { + var command = &cobra.Command{ + Use: "readme", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + } + command.RunE = func(cmd *cobra.Command, args []string) error { + + var readmeTables = make(map[string]string) + + //update system installs + systemList := system.MakeInstall().Commands() + readmeTables["system"] = system.CreateSystemTable(systemList) + + //update apps + appList := install.GetApps() + readmeTables["apps"] = install.CreateAppsTable(appList) + + //update tools + tools := get.MakeTools() + sort.Sort(tools) + readmeTables["tools"] = get.CreateToolsTable(tools, get.MarkdownStyle) + + writeTableToReadme(readmeTables) + + return nil + } + return command +} + +func writeTableToReadme(tables map[string]string) { + + filePath := "README.md" + fileContent, err := os.ReadFile(filePath) + if err != nil { + panic(fmt.Errorf("failed to read file: %w", err)) + } + content := string(fileContent) + + for k, v := range tables { + + startMarker := fmt.Sprintf("", k) + endMarker := fmt.Sprintf("", k) + + startIdx := strings.Index(content, startMarker) + endIdx := strings.Index(content, endMarker) + if startIdx == -1 || endIdx == -1 || startIdx > endIdx { + fmt.Errorf("%s readme markers not found or are in incorrect order", k) + } + + content = content[:startIdx+len(startMarker)] + "\n" + + v + "\n" + + content[endIdx:] + + fmt.Printf("updated %s...\n", k) + } + + err = os.WriteFile(filePath, []byte(content), 0644) + if err != nil { + panic(fmt.Errorf("failed to write to file: %w", err)) + } + + fmt.Println("README updated successfully") +} diff --git a/cmd/update.go b/cmd/update/update.go similarity index 98% rename from cmd/update.go rename to cmd/update/update.go index b8f19454d..5be5a1e81 100644 --- a/cmd/update.go +++ b/cmd/update/update.go @@ -1,7 +1,7 @@ // Copyright (c) arkade author(s) 2022. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -package cmd +package update import ( "fmt" @@ -62,7 +62,10 @@ version twice.`, fmt.Println("\n", aec.Bold.Apply(pkg.SupportMessageShort)) return nil + } + + command.AddCommand(MakeReadme()) return command } diff --git a/main.go b/main.go index 15f3ef2b0..0f803fd5f 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/alexellis/arkade/cmd/chart" "github.com/alexellis/arkade/cmd/oci" "github.com/alexellis/arkade/cmd/system" + "github.com/alexellis/arkade/cmd/update" "github.com/spf13/cobra" ) @@ -27,7 +28,7 @@ func main() { rootCmd.AddCommand(cmd.MakeInstall()) rootCmd.AddCommand(cmd.MakeVersion()) rootCmd.AddCommand(cmd.MakeInfo()) - rootCmd.AddCommand(cmd.MakeUpdate()) + rootCmd.AddCommand(update.MakeUpdate()) rootCmd.AddCommand(cmd.MakeGet()) rootCmd.AddCommand(cmd.MakeUninstall()) rootCmd.AddCommand(cmd.MakeShellCompletion()) diff --git a/pkg/get/table.go b/pkg/get/table.go index 19726f49d..1d61c8bc2 100644 --- a/pkg/get/table.go +++ b/pkg/get/table.go @@ -2,7 +2,7 @@ package get import ( "fmt" - "os" + "strings" "github.com/olekukonko/tablewriter" ) @@ -16,8 +16,11 @@ const ( ) // CreateToolTable creates table to show the avaiable CLI tools -func CreateToolsTable(tools Tools, format TableFormat) { - table := tablewriter.NewWriter(os.Stdout) +func CreateToolsTable(tools Tools, format TableFormat) string { + + tableString := &strings.Builder{} + table := tablewriter.NewWriter(tableString) + //table := tablewriter.NewWriter(os.Stdout) table.SetCaption(true, fmt.Sprintf("There are %d tools, use `arkade get NAME` to download one.", len(tools))) @@ -50,4 +53,6 @@ func CreateToolsTable(tools Tools, format TableFormat) { } table.Render() + + return tableString.String() }