From 73f254f6e50fb3a3ed25e5e3c512b0c969790a00 Mon Sep 17 00:00:00 2001 From: lapwat Date: Sun, 19 Feb 2023 09:45:49 +0100 Subject: [PATCH] [list] add url, path and type in json output --- README.md | 4 ++-- cmd/list.go | 24 +++++++++++++++--------- cmd/version.go | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 56f8d2d..0830752 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ go install github.com/lapwat/papeer@latest ```sh # use platform=darwin for MacOS platform=linux -release=0.6.2 +release=0.6.3 # download and extract curl -L https://github.com/lapwat/papeer/releases/download/v$release/papeer-v$release-$platform-amd64.tar.gz > papeer.tar.gz @@ -154,7 +154,7 @@ sudo mv papeer /usr/local/bin ### Windows -Download [latest release](https://github.com/lapwat/papeer/releases/download/v0.6.0/papeer-v0.6.0-windows-amd64.zip). +Download [latest release](https://github.com/lapwat/papeer/releases/download/v0.6.3/papeer-v0.6.3-windows-amd64.zip). ## MOBI support diff --git a/cmd/list.go b/cmd/list.go index b7e5401..3a03bb5 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -88,6 +88,14 @@ var listCmd = &cobra.Command{ log.Fatal(err) } + // format selector path + pathArray := strings.Split(path, "<") + // reverse path + for i, j := 0, len(pathArray)-1; i < j; i, j = i+1, j-1 { + pathArray[i], pathArray[j] = pathArray[j], pathArray[i] + } + pathFormatted := strings.Join(pathArray, ">") + switch listOpts.output { // render as table @@ -99,15 +107,6 @@ var listCmd = &cobra.Command{ t.Style().Options.SeparateHeader = false t.SetTitle(home.Name()) - - // format selector path - pathArray := strings.Split(path, "<") - // reverse path - for i, j := 0, len(pathArray)-1; i < j; i, j = i+1, j-1 { - pathArray[i], pathArray[j] = pathArray[j], pathArray[i] - } - pathFormatted := strings.Join(pathArray, ">") - t.AppendHeader(table.Row{"#", "Name", fmt.Sprintf("Url [%s]", pathFormatted)}) for index, link := range links { @@ -124,6 +123,13 @@ var listCmd = &cobra.Command{ // render as json case "json": book := make(map[string]interface{}) + book["url"] = base.String() + if pathFormatted == "RSS" { + book["type"] = "RSS" + } else { + book["type"] = "HTML" + } + book["path"] = pathFormatted book["name"] = home.Name() book["chapters"] = links diff --git a/cmd/version.go b/cmd/version.go index 61cbcdc..0c1b870 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of papeer", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("papeer v0.6.2") + fmt.Println("papeer v0.6.3") }, }