-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a subcommand to update that will update the README tables in situ. This will be useful to contributors who are adding system installs / apps / tools as it will remove the need for the existing manual mechanism to update the appropriate tables in the readme. Running `arkade update readme` will update each of the three tables in the readme, ready to be committed with their change. Signed-off-by: Richard Gee <[email protected]>
- Loading branch information
Showing
9 changed files
with
198 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ mc | |
/arkade-* | ||
/faas-cli* | ||
test.out | ||
docker-compose.yaml | ||
docker-compose.yaml* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <!-- start system content --> | ||
systemList := system.MakeInstall().Commands() | ||
readmeTables["system"] = system.CreateSystemTable(systemList) | ||
|
||
//update apps <!-- start apps content --> | ||
appList := install.GetApps() | ||
readmeTables["apps"] = install.CreateAppsTable(appList) | ||
|
||
//update tools <!-- start tools content --> | ||
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("<!-- start %s content -->", k) | ||
endMarker := fmt.Sprintf("<!-- end %s content -->", 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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters