Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: UpCloudLtd/upcloud-cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.0
Choose a base ref
...
head repository: UpCloudLtd/upcloud-cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.3.0
Choose a head ref
  • 11 commits
  • 285 files changed
  • 2 contributors

Commits on Oct 21, 2022

  1. feat(completions): offer no argument completions by default

    For our commands that do not implement argument completion, providing no
    completions rather than filename ones is the better default.
    scop authored and kangasta committed Oct 21, 2022
    Copy the full SHA
    9b53aad View commit details
  2. Copy the full SHA
    e9c93d2 View commit details
  3. Copy the full SHA
    a0436f3 View commit details
  4. Copy the full SHA
    522bf81 View commit details
  5. Copy the full SHA
    e6ae880 View commit details
  6. Copy the full SHA
    1ddfaef View commit details

Commits on Oct 25, 2022

  1. refactor(docs): generate documentation with Material for MkDocs (#188)

    Remove previous Jekyll based GitHub pages and replace those with MkDocs
    based solution that uses Material for MkDocs theme with few custom
    overrides. Remove generated documentation from `main` branch.
    
    In addition, add custom logic for markdown command reference generation
    in order to:
    - list command aliases in markdown files,
    - present command options in tables for increased accessibility,
    - display only long or short command description similarly than in `--help` outputs,
    - and use `*cobra.Command` instead of output filename as input to file prefix function.
    kangasta authored Oct 25, 2022
    Copy the full SHA
    469512f View commit details

Commits on Nov 4, 2022

  1. Copy the full SHA
    094f5e3 View commit details

Commits on Nov 9, 2022

  1. feat: parse version from BuildInfo if it was not defined during bui…

    …ld (#192)
    
    This adds meaningful version info also to binaries created with `go
    install` without defining `-ldflags` to override `.../config.Version`
    variable.
    kangasta authored Nov 9, 2022
    Copy the full SHA
    b3963a4 View commit details

Commits on Nov 10, 2022

  1. feat(containers): use alpine as base to have shell in our images (#193)

    This makes the `upcloud/upctl` container more suitable for usage in CI
    pipelines. This also adds ~5 MB (size of `alpine:3.16` vs. `scratch`) to
    the image size and thus the image size will be ~16 MB in total.
    kangasta authored Nov 10, 2022
    Copy the full SHA
    e0c7606 View commit details

Commits on Nov 11, 2022

  1. Copy the full SHA
    dfefd8b View commit details
Showing with 1,166 additions and 3,614 deletions.
  1. +33 −0 .ci/docs/generate_command_reference_nav.py
  2. +22 −0 .ci/docs/main.go
  3. +199 −0 .ci/docs/md.go
  4. +1 −0 .ci/docs/overrides/partials/actions.html
  5. +14 −0 .ci/docs/overrides/partials/footer.html
  6. +16 −0 .ci/docs/overrides/partials/logo.html
  7. +5 −0 .ci/docs/overrides/partials/toc-item.html
  8. +9 −0 .ci/docs/sort.go
  9. +38 −0 .github/workflows/docs.yml
  10. +0 −25 .github/workflows/document.yml
  11. +6 −0 .gitignore
  12. +2 −1 .goreleaser.yml
  13. +14 −1 CHANGELOG.md
  14. +10 −7 Dockerfile
  15. +4 −9 Dockerfile.goreleaser
  16. +25 −4 Makefile
  17. +13 −1 README.md
  18. +0 −1 _config.yml
  19. +0 −22 cmd/doc-gen/main.go
  20. +1 −1 cmd/upctl/main.go
  21. +26 −0 docs/extra.css
  22. BIN docs/favicon.png
  23. +4 −0 docs/index.md
  24. +0 −46 docs/upctl.md
  25. +0 −31 docs/upctl_account.md
  26. +0 −36 docs/upctl_account_show.md
  27. +0 −36 docs/upctl_completion.md
  28. +0 −38 docs/upctl_database.md
  29. +0 −32 docs/upctl_database_connection.md
  30. +0 −39 docs/upctl_database_connection_cancel.md
  31. +0 −36 docs/upctl_database_connection_list.md
  32. +0 −37 docs/upctl_database_delete.md
  33. +0 −36 docs/upctl_database_list.md
  34. +0 −37 docs/upctl_database_plans.md
  35. +0 −38 docs/upctl_database_show.md
  36. +0 −38 docs/upctl_database_start.md
  37. +0 −38 docs/upctl_database_stop.md
  38. +0 −36 docs/upctl_database_types.md
  39. +0 −35 docs/upctl_ip-address.md
  40. +0 −45 docs/upctl_ip-address_assign.md
  41. +0 −36 docs/upctl_ip-address_list.md
  42. +0 −39 docs/upctl_ip-address_modify.md
  43. +0 −37 docs/upctl_ip-address_remove.md
  44. +0 −37 docs/upctl_ip-address_show.md
  45. +0 −33 docs/upctl_loadbalancer.md
  46. +0 −37 docs/upctl_loadbalancer_delete.md
  47. +0 −36 docs/upctl_loadbalancer_list.md
  48. +0 −37 docs/upctl_loadbalancer_show.md
  49. +0 −35 docs/upctl_network.md
  50. +0 −49 docs/upctl_network_create.md
  51. +0 −38 docs/upctl_network_delete.md
  52. +0 −44 docs/upctl_network_list.md
  53. +0 −48 docs/upctl_network_modify.md
  54. +0 −38 docs/upctl_network_show.md
  55. +0 −35 docs/upctl_router.md
  56. +0 −38 docs/upctl_router_create.md
  57. +0 −37 docs/upctl_router_delete.md
  58. +0 −40 docs/upctl_router_list.md
  59. +0 −38 docs/upctl_router_modify.md
  60. +0 −38 docs/upctl_router_show.md
  61. +0 −44 docs/upctl_server.md
  62. +0 −73 docs/upctl_server_create.md
  63. +0 −39 docs/upctl_server_delete.md
  64. +0 −36 docs/upctl_server_eject.md
  65. +0 −33 docs/upctl_server_firewall.md
  66. +0 −60 docs/upctl_server_firewall_create.md
  67. +0 −37 docs/upctl_server_firewall_delete.md
  68. +0 −38 docs/upctl_server_firewall_show.md
  69. +0 −39 docs/upctl_server_list.md
  70. +0 −37 docs/upctl_server_load.md
  71. +0 −58 docs/upctl_server_modify.md
  72. +0 −33 docs/upctl_server_network-interface.md
  73. +0 −48 docs/upctl_server_network-interface_create.md
  74. +0 −38 docs/upctl_server_network-interface_delete.md
  75. +0 −42 docs/upctl_server_network-interface_modify.md
  76. +0 −36 docs/upctl_server_plans.md
  77. +0 −39 docs/upctl_server_restart.md
  78. +0 −39 docs/upctl_server_show.md
  79. +0 −38 docs/upctl_server_start.md
  80. +0 −41 docs/upctl_server_stop.md
  81. +0 −32 docs/upctl_server_storage.md
  82. +0 −44 docs/upctl_server_storage_attach.md
  83. +0 −38 docs/upctl_server_storage_detach.md
  84. +0 −39 docs/upctl_storage.md
  85. +0 −32 docs/upctl_storage_backup.md
  86. +0 −38 docs/upctl_storage_backup_create.md
  87. +0 −37 docs/upctl_storage_backup_restore.md
  88. +0 −41 docs/upctl_storage_clone.md
  89. +0 −45 docs/upctl_storage_create.md
  90. +0 −38 docs/upctl_storage_delete.md
  91. +0 −48 docs/upctl_storage_import.md
  92. +0 −44 docs/upctl_storage_list.md
  93. +0 −44 docs/upctl_storage_modify.md
  94. +0 −38 docs/upctl_storage_show.md
  95. +0 −40 docs/upctl_storage_templatise.md
  96. +0 −36 docs/upctl_version.md
  97. +0 −31 docs/upctl_zone.md
  98. +0 −36 docs/upctl_zone_list.md
  99. +1 −3 go.mod
  100. +0 −2 go.sum
  101. +1 −1 internal/commands/account/account.go
  102. +2 −2 internal/commands/account/show.go
  103. +4 −4 internal/commands/account/show_test.go
  104. +17 −17 internal/commands/all/all.go
  105. +8 −4 internal/commands/command.go
  106. +5 −5 internal/commands/database/connection/cancel.go
  107. +4 −4 internal/commands/database/connection/cancel_test.go
  108. +1 −1 internal/commands/database/connection/connection.go
  109. +5 −5 internal/commands/database/connection/list.go
  110. +1 −1 internal/commands/database/database.go
  111. +4 −4 internal/commands/database/delete.go
  112. +3 −3 internal/commands/database/delete_test.go
  113. +10 −5 internal/commands/database/list.go
  114. +37 −0 internal/commands/database/list_test.go
  115. +4 −2 internal/commands/database/plans.go
  116. +4 −4 internal/commands/database/plans_test.go
  117. +6 −6 internal/commands/database/show.go
  118. +4 −4 internal/commands/database/start.go
  119. +4 −4 internal/commands/database/start_test.go
  120. +4 −4 internal/commands/database/stop.go
  121. +4 −4 internal/commands/database/stop_test.go
  122. +2 −2 internal/commands/database/types.go
  123. +1 −1 internal/commands/error.go
  124. +3 −3 internal/commands/executor.go
  125. +2 −2 internal/commands/executor_test.go
  126. +4 −4 internal/commands/ipaddress/assign.go
  127. +3 −3 internal/commands/ipaddress/assign_test.go
  128. +1 −1 internal/commands/ipaddress/ip_address.go
  129. +4 −4 internal/commands/ipaddress/list.go
  130. +4 −4 internal/commands/ipaddress/modify.go
  131. +3 −3 internal/commands/ipaddress/modify_test.go
  132. +4 −4 internal/commands/ipaddress/remove.go
  133. +3 −3 internal/commands/ipaddress/remove_test.go
  134. +6 −6 internal/commands/ipaddress/show.go
  135. +4 −4 internal/commands/ipaddress/show_test.go
  136. +4 −4 internal/commands/loadbalancer/delete.go
  137. +3 −3 internal/commands/loadbalancer/delete_test.go
  138. +4 −4 internal/commands/loadbalancer/list.go
  139. +1 −1 internal/commands/loadbalancer/loadbalancer.go
  140. +6 −6 internal/commands/loadbalancer/show.go
  141. +4 −4 internal/commands/network/create.go
  142. +4 −4 internal/commands/network/create_test.go
  143. +4 −4 internal/commands/network/delete.go
  144. +3 −3 internal/commands/network/delete_test.go
  145. +4 −4 internal/commands/network/list.go
  146. +5 −5 internal/commands/network/list_test.go
  147. +5 −5 internal/commands/network/modify.go
  148. +4 −4 internal/commands/network/modify_test.go
  149. +2 −2 internal/commands/network/network.go
  150. +6 −6 internal/commands/network/show.go
  151. +4 −4 internal/commands/network/show_test.go
  152. +3 −3 internal/commands/root/completion.go
  153. +4 −4 internal/commands/root/version.go
  154. +3 −3 internal/commands/router/create.go
  155. +4 −4 internal/commands/router/create_test.go
  156. +4 −4 internal/commands/router/delete.go
  157. +3 −3 internal/commands/router/delete_test.go
  158. +4 −4 internal/commands/router/list.go
  159. +4 −4 internal/commands/router/modify.go
  160. +4 −4 internal/commands/router/modify_test.go
  161. +1 −1 internal/commands/router/router.go
  162. +5 −5 internal/commands/router/show.go
  163. +5 −5 internal/commands/router/show_test.go
  164. +4 −4 internal/commands/runcommand.go
  165. +5 −5 internal/commands/runcommand_test.go
  166. +6 −6 internal/commands/server/create.go
  167. +5 −5 internal/commands/server/create_test.go
  168. +5 −5 internal/commands/server/delete.go
  169. +3 −3 internal/commands/server/delete_test.go
  170. +4 −4 internal/commands/server/eject.go
  171. +3 −3 internal/commands/server/eject_test.go
  172. +6 −9 internal/commands/server/firewall/create.go
  173. +4 −4 internal/commands/server/firewall/create_test.go
  174. +4 −4 internal/commands/server/firewall/delete.go
  175. +4 −4 internal/commands/server/firewall/delete_test.go
  176. +1 −1 internal/commands/server/firewall/server_firewall.go
  177. +6 −6 internal/commands/server/firewall/show.go
  178. +4 −4 internal/commands/server/firewall/show_test.go
  179. +5 −5 internal/commands/server/list.go
  180. +4 −4 internal/commands/server/list_test.go
  181. +5 −5 internal/commands/server/load.go
  182. +4 −4 internal/commands/server/load_test.go
  183. +5 −5 internal/commands/server/modify.go
  184. +3 −3 internal/commands/server/modify_test.go
  185. +6 −6 internal/commands/server/networkinterface/create.go
  186. +3 −3 internal/commands/server/networkinterface/create_test.go
  187. +4 −4 internal/commands/server/networkinterface/delete.go
  188. +4 −4 internal/commands/server/networkinterface/delete_test.go
  189. +4 −4 internal/commands/server/networkinterface/modify.go
  190. +4 −4 internal/commands/server/networkinterface/modify_test.go
  191. +2 −2 internal/commands/server/networkinterface/network_interface.go
  192. +2 −2 internal/commands/server/plan_list.go
  193. +4 −4 internal/commands/server/restart.go
  194. +3 −3 internal/commands/server/restart_test.go
  195. +1 −1 internal/commands/server/server.go
  196. +6 −6 internal/commands/server/show.go
  197. +4 −4 internal/commands/server/show_test.go
  198. +4 −4 internal/commands/server/start.go
  199. +3 −3 internal/commands/server/start_test.go
  200. +5 −5 internal/commands/server/stop.go
  201. +3 −3 internal/commands/server/stop_test.go
  202. +6 −6 internal/commands/server/storage/attach.go
  203. +4 −4 internal/commands/server/storage/attach_test.go
  204. +4 −4 internal/commands/server/storage/detach.go
  205. +4 −4 internal/commands/server/storage/detach_test.go
  206. +1 −1 internal/commands/server/storage/server_storage.go
  207. +1 −1 internal/commands/storage/backup/backup.go
  208. +5 −5 internal/commands/storage/backup/create.go
  209. +4 −4 internal/commands/storage/backup/create_test.go
  210. +4 −4 internal/commands/storage/backup/restore.go
  211. +3 −3 internal/commands/storage/backup/restore_test.go
  212. +4 −4 internal/commands/storage/clone.go
  213. +4 −4 internal/commands/storage/clone_test.go
  214. +3 −3 internal/commands/storage/create.go
  215. +4 −4 internal/commands/storage/create_test.go
  216. +4 −4 internal/commands/storage/delete.go
  217. +3 −3 internal/commands/storage/delete_test.go
  218. +5 −5 internal/commands/storage/import.go
  219. +4 −4 internal/commands/storage/import_test.go
  220. +5 −5 internal/commands/storage/list.go
  221. +4 −4 internal/commands/storage/list_test.go
  222. +5 −5 internal/commands/storage/modify.go
  223. +3 −3 internal/commands/storage/modify_test.go
  224. +6 −6 internal/commands/storage/show.go
  225. +4 −4 internal/commands/storage/show_test.go
  226. +1 −1 internal/commands/storage/storage.go
  227. +6 −6 internal/commands/storage/templatize.go
  228. +4 −4 internal/commands/storage/templatize_test.go
  229. +10 −1 internal/commands/util.go
  230. +3 −3 internal/commands/zone/list.go
  231. +4 −4 internal/commands/zone/list_test.go
  232. +1 −1 internal/commands/zone/zone.go
  233. +1 −1 internal/completion/completionprovider.go
  234. +20 −1 internal/completion/database.go
  235. +2 −2 internal/completion/database_test.go
  236. +1 −1 internal/completion/helpers_test.go
  237. +1 −4 internal/completion/ipaddress.go
  238. +2 −2 internal/completion/ipaddress_test.go
  239. +1 −1 internal/completion/loadbalancer.go
  240. +2 −2 internal/completion/loadbalancer_test.go
  241. +1 −1 internal/completion/network.go
  242. +2 −2 internal/completion/network_test.go
  243. +1 −1 internal/completion/router.go
  244. +2 −2 internal/completion/router_test.go
  245. +1 −1 internal/completion/server.go
  246. +2 −2 internal/completion/server_test.go
  247. +1 −1 internal/completion/storage.go
  248. +2 −2 internal/completion/storage_test.go
  249. +37 −2 internal/config/config.go
  250. +7 −7 internal/core/core.go
  251. +1 −1 internal/format/common.go
  252. +4 −4 internal/mockexecute/mockexecute.go
  253. +1 −1 internal/output/combined.go
  254. +1 −1 internal/output/combined_test.go
  255. +1 −1 internal/output/details.go
  256. +1 −1 internal/output/details_test.go
  257. +1 −1 internal/output/error_test.go
  258. +1 −1 internal/output/marshaledwithhumandetails_test.go
  259. +1 −1 internal/output/marshaledwithhumanoutput_test.go
  260. +1 −1 internal/output/onlymarshaled_test.go
  261. +1 −1 internal/output/output_test.go
  262. +1 −1 internal/output/render.go
  263. +2 −2 internal/output/render_test.go
  264. +2 −2 internal/output/table.go
  265. +1 −1 internal/output/table_test.go
  266. +1 −1 internal/resolver/completion.go
  267. +1 −1 internal/resolver/database.go
  268. +2 −2 internal/resolver/database_test.go
  269. +1 −1 internal/resolver/ipaddress.go
  270. +2 −2 internal/resolver/ipaddress_test.go
  271. +1 −1 internal/resolver/loadbalancer.go
  272. +2 −2 internal/resolver/loadbalancer_test.go
  273. +1 −1 internal/resolver/network.go
  274. +2 −2 internal/resolver/network_test.go
  275. +1 −1 internal/resolver/resolver.go
  276. +1 −1 internal/resolver/router.go
  277. +2 −2 internal/resolver/router_test.go
  278. +1 −1 internal/resolver/server.go
  279. +2 −2 internal/resolver/server_test.go
  280. +1 −1 internal/resolver/storage.go
  281. +2 −2 internal/resolver/storage_test.go
  282. +1 −1 internal/ui/datatable.go
  283. +1 −1 internal/ui/details.go
  284. +31 −0 mkdocs.base.yaml
  285. +3 −0 requirements.txt
33 changes: 33 additions & 0 deletions .ci/docs/generate_command_reference_nav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

def withBase(name, base):
if base:
return f'{base} {name}'
return name

def parse_name(name):
return name.replace('_', ' ').replace('.md', '').replace('index', '')

def generateNav(path, base=''):
pages = []

for i in sorted(os.scandir(path), key=lambda i: parse_name(i.name)):
if i.is_file():
name = parse_name(i.name)
pages.append({withBase(name, base): i.path})
if i.is_dir():
name = i.name.replace('_', ' ')
pages.append({withBase(name, base): generateNav(i.path, base=name.replace('upctl ', ''))})

return pages

if __name__ == '__main__':
os.chdir('docs/')
nav = generateNav('commands_reference/')
os.chdir('..')

with open("mkdocs.base.yaml") as f:
config = f.read().replace('Commands reference: []', f'Commands reference: {nav}')

with open("mkdocs.yaml", "w") as f:
f.write(config)
22 changes: 22 additions & 0 deletions .ci/docs/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"log"

"github.com/UpCloudLtd/upcloud-cli/v2/internal/core"
"github.com/spf13/cobra"
)

const (
docPath = "./docs/commands_reference"
)

func main() {
rootCmd := core.BuildCLI()

frontMatterFunc := func(cmd *cobra.Command) string { return "---\ntitle: \"" + cmd.CommandPath() + "\"\n---\n" }
err := genMarkdownTree(&rootCmd, docPath, frontMatterFunc)
if err != nil {
log.Fatal(err)
}
}
199 changes: 199 additions & 0 deletions .ci/docs/md.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package main

import (
"bytes"
"fmt"
"io"
"os"
"path"
"path/filepath"
"sort"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

// formatFlags formats options and aliases as list of code elements. E.g., ["--help", "-h"] becomes "`--help`, `-h`".
func formatFlags(input []string) string {
return fmt.Sprintf("`%s`", strings.Join(input, "`, `"))
}

// formatDescription replaces line breaks in descriptions with <br/> elements to avoid breaking table formatting.
func formatDescription(input string) string {
return strings.Replace(input, "\n", "<br/>", -1)
}

// sprintOptionsTable renders options in table to make them more accessible.
func sprintOptionsTable(flags *pflag.FlagSet) string {
output := "| Option | Description |\n"
output += "| ------ | ----------- |\n"

flags.VisitAll(func(flag *pflag.Flag) {
flags := []string{"--" + flag.Name}
if flag.Shorthand != "" && flag.ShorthandDeprecated == "" {
flags = append(flags, "-"+flag.Shorthand)
}

description := flag.Usage
if flag.DefValue != "" {
description += fmt.Sprintf("\nDefault: `%s`", flag.DefValue)
}

row := fmt.Sprintf("| %s | %s |\n", formatFlags(flags), formatDescription(description))
output += row
})

return output
}

func sprintOptions(cmd *cobra.Command, name string) string {
output := ""

flags := cmd.NonInheritedFlags()
if flags.HasAvailableFlags() {
output += "## Options\n\n"
output += sprintOptionsTable(flags)
output += "\n"
}

parentFlags := cmd.InheritedFlags()
if parentFlags.HasAvailableFlags() {
output += "## Global options\n\n"
output += sprintOptionsTable(parentFlags)
output += "\n"
}

return output
}

func isHiddenCommand(cmd *cobra.Command) bool {
return !cmd.IsAvailableCommand() || cmd.IsAdditionalHelpTopicCommand()
}

func hasChildCommands(cmd *cobra.Command) bool {
for _, c := range cmd.Commands() {
if isHiddenCommand(c) {
continue
}
return true
}
return false
}

func hasRelatedCommands(cmd *cobra.Command) bool {
if cmd.HasParent() {
return true
}
return hasChildCommands(cmd)
}

func getFilename(cmd *cobra.Command) string {
cmdpath := cmd.CommandPath()
if hasChildCommands(cmd) && strings.Contains(cmdpath, " ") {
cmdpath = cmdpath + " index"
}
basename := strings.Replace(cmdpath, " ", "_", 1)
return strings.ReplaceAll(basename, " ", "/") + ".md"
}

func getRelativeLink(current, target *cobra.Command) string {
depth := strings.Count(getFilename(current), "/")
return strings.Repeat("../", depth) + getFilename(target)
}

func genMarkdown(cmd *cobra.Command, w io.Writer) error {
cmd.InitDefaultHelpCmd()
cmd.InitDefaultHelpFlag()

buf := new(bytes.Buffer)
name := cmd.CommandPath()

buf.WriteString("# " + name + "\n\n")
if len(cmd.Long) > 0 {
buf.WriteString(cmd.Long + "\n\n")
} else {
buf.WriteString(cmd.Short + "\n\n")
}

if cmd.Runnable() {
buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.UseLine()))
}

if len(cmd.Aliases) > 0 {
buf.WriteString("## Aliases\n\n")
buf.WriteString(fmt.Sprintf("%s\n\n", formatFlags(cmd.Aliases)))
}

if len(cmd.Example) > 0 {
buf.WriteString("## Examples\n\n")
buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.Example))
}

buf.WriteString(sprintOptions(cmd, name))

if hasRelatedCommands(cmd) {
buf.WriteString("## Related commands\n\n")
buf.WriteString("| Command | Description |\n")
buf.WriteString("| ------- | ----------- |\n")

if cmd.HasParent() {
parent := cmd.Parent()
pname := parent.CommandPath()
link := getRelativeLink(cmd, parent)
buf.WriteString(fmt.Sprintf("| [%s](%s) | %s |\n", pname, link, formatDescription(parent.Short)))
cmd.VisitParents(func(c *cobra.Command) {
if c.DisableAutoGenTag {
cmd.DisableAutoGenTag = c.DisableAutoGenTag
}
})
}

children := cmd.Commands()
sort.Sort(byName(children))

for _, child := range children {
if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {
continue
}
cname := name + " " + child.Name()
link := getRelativeLink(cmd, child)
buf.WriteString(fmt.Sprintf("| [%s](%s) | %s |\n", cname, link, formatDescription(child.Short)))
}
buf.WriteString("\n")
}

_, err := buf.WriteTo(w)
return err
}

func genMarkdownTree(cmd *cobra.Command, dir string, filePrepender func(*cobra.Command) string) error {
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
continue
}
if err := genMarkdownTree(c, dir, filePrepender); err != nil {
return err
}
}

basename := getFilename(cmd)
filename := filepath.Join(dir, basename)
directory := path.Dir(filename)
if err := os.MkdirAll(directory, 0755); err != nil {
return err
}
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()

if _, err := io.WriteString(f, filePrepender(cmd)); err != nil {
return err
}
if err := genMarkdown(cmd, f); err != nil {
return err
}
return nil
}
1 change: 1 addition & 0 deletions .ci/docs/overrides/partials/actions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- Hide edit button as command reference and changelog do not exist on main branch -->
14 changes: 14 additions & 0 deletions .ci/docs/overrides/partials/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Removes previous and next links -->

<footer class="md-footer">
<!-- Further information -->
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
{% include "partials/copyright.html" %}

<!-- Social links -->
{% if config.extra.social %} {% include "partials/social.html" %} {% endif
%}
</div>
</div>
</footer>
16 changes: 16 additions & 0 deletions .ci/docs/overrides/partials/logo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<svg
height="26"
fill="none"
xmlns="http://www.w3.org/2000/svg"
width="54"
viewBox="0 0 54 26"
>
<path
d="M47.131 13.26a3.953 3.953 0 013.952 3.958 3.964 3.964 0 01-3.952 3.958H18.844V10.888H20.7v8.446h26.447a2.112 2.112 0 002.112-2.116c0-1.17-.944-2.115-2.112-2.115H22.54V13.26h24.591z"
fill="currentColor"
></path>
<path
d="M28.892 1.112H18.844v4.231H20.7V2.955h8.192c1.168 0 2.112.946 2.112 2.116 0 1.17-.944 2.115-2.112 2.115H4.541a3.953 3.953 0 00-3.952 3.958 3.964 3.964 0 003.952 3.959h12.431V13.26H4.542a2.112 2.112 0 01-2.112-2.116c0-1.17.944-2.115 2.112-2.115h24.335a3.953 3.953 0 003.952-3.958c0-2.18-1.776-3.959-3.936-3.959z"
fill="currentColor"
></path>
</svg>
5 changes: 5 additions & 0 deletions .ci/docs/overrides/partials/toc-item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Limit TOC depth to 1 -->

<li class="md-nav__item">
<a href="{{ toc_item.url }}" class="md-nav__link"> {{ toc_item.title }} </a>
</li>
9 changes: 9 additions & 0 deletions .ci/docs/sort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import "github.com/spf13/cobra"

type byName []*cobra.Command

func (s byName) Len() int { return len(s) }
func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }
38 changes: 38 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Docs
on:
push:
branches:
- main
- test-docs-generator # for testing

jobs:
generate-and-deploy:
name: Generate and deploy
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Checkout head
uses: actions/checkout@v3
- name: Generate documentation
run: make docs
- name: Store generated MkDocs site
uses: actions/upload-artifact@v3
with:
name: mkdocs-site
path: site
retention-days: 7
- name: Deploy to pages
if: ${{ github.ref_name == 'main' }}
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: site
CLEAN: true
25 changes: 0 additions & 25 deletions .github/workflows/document.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -34,3 +34,9 @@ dist/
# Go workspace files
/go.work
/go.work.sum

# Generated docs content
/docs/commands_reference/
/docs/CHANGELOG.md
/mkdocs.yaml
/site/
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ before:
builds:
- env:
- CGO_ENABLED=0
- GO_MODULE_NAME=github.com/UpCloudLtd/upcloud-cli
- GO_MODULE_NAME=github.com/UpCloudLtd/upcloud-cli/v2
goos:
- linux
- windows
@@ -214,3 +214,4 @@ dockers:
- "--label=org.opencontainers.image.title=upctl"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/UpCloudLtd/upcloud-cli.git"
Loading