2025-10-04 00:20:04 +01:00
|
|
|
package cli
|
2025-09-23 23:56:47 +01:00
|
|
|
|
|
|
|
import (
|
2025-09-30 07:00:00 +01:00
|
|
|
"fmt"
|
2025-09-30 18:00:00 +01:00
|
|
|
"log"
|
2025-09-30 07:00:00 +01:00
|
|
|
"strings"
|
|
|
|
|
2025-09-30 23:49:23 +01:00
|
|
|
"code.oliverdavies.uk/opdavies/cmd-zet/internal/json"
|
|
|
|
"code.oliverdavies.uk/opdavies/cmd-zet/internal/zet"
|
2025-10-01 00:13:55 +01:00
|
|
|
"github.com/spf13/cobra"
|
2025-09-23 23:56:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var titlesCmd = &cobra.Command{
|
2025-09-30 00:48:16 +01:00
|
|
|
Use: "titles",
|
2025-09-23 23:56:47 +01:00
|
|
|
Aliases: []string{"t"},
|
2025-09-30 00:48:16 +01:00
|
|
|
Short: "Print IDs and titles of zettels",
|
2025-09-30 18:00:00 +01:00
|
|
|
Long: `Print the IDs and titles of all zettels.
|
|
|
|
|
|
|
|
If -j or --json is added, the results will be in JSON format.`,
|
2025-10-04 00:20:04 +01:00
|
|
|
Run: func(cli *cobra.Command, args []string) {
|
2025-09-30 23:49:23 +01:00
|
|
|
zets := zet.GetAllZets()
|
2025-09-23 23:56:47 +01:00
|
|
|
|
2025-09-30 23:49:23 +01:00
|
|
|
result := zet.ParseZetList(zets)
|
2025-09-30 07:00:00 +01:00
|
|
|
|
2025-09-30 18:00:00 +01:00
|
|
|
if jsonOutput {
|
2025-09-30 23:49:23 +01:00
|
|
|
json, err := json.AsJSON(result)
|
2025-09-30 18:00:00 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(json)
|
|
|
|
} else {
|
|
|
|
fmt.Println(strings.Join(result, "\n"))
|
|
|
|
}
|
2025-09-23 23:56:47 +01:00
|
|
|
},
|
|
|
|
}
|
2025-09-30 18:00:00 +01:00
|
|
|
|
|
|
|
func init() {
|
2025-10-04 00:20:04 +01:00
|
|
|
rootCmd.AddCommand(titlesCmd)
|
|
|
|
|
2025-09-30 18:00:00 +01:00
|
|
|
titlesCmd.Flags().BoolVarP(&jsonOutput, "json", "j", false, "Output results in JSON format")
|
|
|
|
}
|