Something went wrong. Try again.
minimal set of lexicons for book tracking
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374/*Copyright © 2026 Hector Alfaro <hector@hectorsector.com>*/package cmd
import ( "fmt" "os"
"github.com/spf13/cobra" "tangled.org/hectorsector.com/books/cli/internal/apperrors" "tangled.org/hectorsector.com/books/cli/internal/lexicon" "tangled.org/hectorsector.com/books/cli/internal/store")
var listCmd = &cobra.Command{ Use: "list", Short: "List the books in our local record.", Run: func(cmd *cobra.Command, args []string) { storePath, _ := cmd.Root().PersistentFlags().GetString("store")
books, err := store.Load(storePath) if err != nil { fmt.Fprintf(os.Stderr, "loading store at %s:\n%s", storePath, apperrors.FormatError(err)) os.Exit(1) } fmt.Println("📂 Loaded from store.")
books = store.Filter(books, filtersFromFlags(cmd)...) n, _ := cmd.Flags().GetInt("count") if n > 0 && n < len(books) { books = books[:n] }
full, _ := cmd.Flags().GetBool("full") if full { printFull(books) } else { printSummary(books) } },}
func printFull(books []store.Book) { for _, b := range books { fmt.Printf("%-40.40s %-25.25s %-12.12s %-13.13s %-20.20s %-50.50s %s\n", b.Title, b.Author, lexicon.DisplayStatus(b.LexiconStatus), b.ISBN, b.OLWorkID, b.BookURI, b.StatusURI) }}
func printSummary(books []store.Book) { for _, b := range books { fmt.Printf("%s by %s [%s]\n", b.Title, b.Author, lexicon.DisplayStatus(b.LexiconStatus)) }}
func init() { rootCmd.AddCommand(listCmd)
listCmd.Flags().Bool("full", false, "show all fields")
// filters listCmd.Flags().IntP("count", "n", 0, "limit results, (0=all)") listCmd.Flags().String("title", "", "filter by title (partial match)") listCmd.Flags().String("author", "", "filter by author (partial match)") listCmd.Flags().String("isbn", "", "filter by ISBN") listCmd.Flags().Bool("no-isbn", false, "filter books with no ISBN") listCmd.Flags().String("status", "", "filter by lexicon status (wantToRead, reading, finished, didNotFinish, paused)") listCmd.Flags().Bool("no-status", false, "filter books with no status") listCmd.Flags().String("olworkid", "", "filter by OL work ID") listCmd.Flags().Bool("no-olworkid", false, "filter books with no OL work ID") listCmd.Flags().Bool("published", false, "filter books that have been published") listCmd.Flags().Bool("not-published", false, "filter books that have not been published")}