diff options
| author | Shulhan <ms@kilabit.info> | 2025-06-01 14:31:12 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-06-01 14:32:06 +0700 |
| commit | 19b2e2d1ac0fd8a88af6b0da3d00017e4ee31c06 (patch) | |
| tree | 3648ad12458e21a11cea25e2bef0a9fcd5a4604c | |
| parent | 43408bb5faae9d0458a3f0a9f97741ce3222eb97 (diff) | |
| download | jarink-19b2e2d1ac0fd8a88af6b0da3d00017e4ee31c06.tar.xz | |
all: go embed the README and use it on the CLI for help command
| -rw-r--r-- | README | 81 | ||||
| -rw-r--r-- | cmd/jarink/main.go | 77 | ||||
| -rw-r--r-- | jarink.go | 11 |
3 files changed, 67 insertions, 102 deletions
@@ -1,54 +1,63 @@ = Jarink -Jarink is a program to help web administrator to maintains their website. +Jarink is a program to help web administrator and developers to inspect +and maintains their website. == Synopsis - jarink [OPTIONS] <COMMAND> <args...> + jarink [OPTIONS] <COMMAND> <args...> Available commands, - brokenlinks - scan the website for broken links (page and images). + brokenlinks - scan the website for broken links (page and images). + help - print the usage of the command. == Usage [OPTIONS] brokenlinks URL - Start scanning for broken links on the web server pointed by URL. - Invalid links will be scanned on anchor href attribute - ("<a href=...>") or on the image src attribute ("<img src=..."). + Start scanning for broken links on the web server pointed by URL. + Links will be scanned on anchor href attribute ("<a href=...>") or + on the image src attribute ("<img src=..."). - Once finished it will print the page and list of broken links inside - that page in JSON format. + Once finished it will print the page and list of broken links in + JSON format to standard output. - This command accept the following options, + This command accept the following options, - -verbose : print the page that being scanned. + -verbose : print the page that being scanned to standard + error. - Example, + Example, - $ jarink scan https://kilabit.info - { - "https://kilabit.info/some/page": [ - { - "Link": "https://kilabit.info/some/page/image.png", - "Code": 404 - }, - { - "Link": "https://external.com/link", - "Error": "Internal server error", - "Code": 500 - } - ], - "https://kilabit.info/another/page": [ - { - "Link": "https://kilabit.info/another/page/image.png", - "Code": 404 - }, - { - "Link": "https://external.org/link", - "Error": "Internal server error", - "Code": 500 - } - ] - } + $ jarink brokenlinks https://kilabit.info + { + "https://kilabit.info/some/page": [ + { + "Link": "https://kilabit.info/some/page/image.png", + "Code": 404 + }, + { + "Link": "https://external.com/link", + "Error": "Internal server error", + "Code": 500 + } + ], + "https://kilabit.info/another/page": [ + { + "Link": "https://kilabit.info/another/page/image.png", + "Code": 404 + }, + { + "Link": "https://external.org/link", + "Error": "Internal server error", + "Code": 500 + } + ] + } + +== Notes + +jarink version 0.1.0. + +Source code - https://git.sr.ht/~shulhan/jarink diff --git a/cmd/jarink/main.go b/cmd/jarink/main.go index d73cd1a..4f4d206 100644 --- a/cmd/jarink/main.go +++ b/cmd/jarink/main.go @@ -25,17 +25,15 @@ func main() { flag.Parse() var cmd = flag.Arg(0) - if cmd == "" { - goto invalid_command - } - cmd = strings.ToLower(cmd) - if cmd == "brokenlinks" { + switch cmd { + case `brokenlinks`: var brokenlinksOpts = jarink.BrokenlinksOptions{ Url: flag.Arg(1), IsVerbose: optVerbose, } if brokenlinksOpts.Url == "" { + log.Printf(`Missing argument URL to be scanned.`) goto invalid_command } @@ -53,69 +51,16 @@ func main() { } fmt.Printf("%s\n", resultJson) return - } - -invalid_command: - usage() - os.Exit(1) -} - -func usage() { - log.Println(`= Jarink - -Jarink is a program to help web administrator to maintains their website. - -== Synopsis - - jarink [OPTIONS] <COMMAND> <args...> -Available commands, - - brokenlinks - scan the website for broken links (page and images). - -== Usage - -[OPTIONS] brokenlinks URL - - Start scanning for broken links on the web server pointed by URL. - Invalid links will be scanned on anchor href attribute - ("<a href=...>") or on the image src attribute ("<img src=..."). - - Once finished it will print the page and list of broken links inside - that page in JSON format. - - This command accept the following options, - - -verbose : print the page that being scanned. - - Example, + case `help`: + log.Println(jarink.GoEmbedReadme) + return - $ jarink scan https://kilabit.info - { - "https://kilabit.info/some/page": [ - { - "Link": "https://kilabit.info/some/page/image.png", - "Code": 404 - }, - { - "Link": "https://external.com/link", - "Error": "Internal server error", - "Code": 500 - } - ], - "https://kilabit.info/another/page": [ - { - "Link": "https://kilabit.info/another/page/image.png", - "Code": 404 - }, - { - "Link": "https://external.org/link", - "Error": "Internal server error", - "Code": 500 - } - ] + default: + log.Printf(`Missing or invalid command %q`, cmd) } --- -jarink v` + jarink.Version) +invalid_command: + log.Printf(`Run "jarink help" for usage.`) + os.Exit(1) } diff --git a/jarink.go b/jarink.go new file mode 100644 index 0000000..141becb --- /dev/null +++ b/jarink.go @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-only + +package jarink + +import ( + _ "embed" +) + +//go:embed README +var GoEmbedReadme string |
