Rename variables

This commit is contained in:
Tim Van Baak 2025-01-29 09:07:57 -08:00
parent f804299180
commit 7ca6ccfaf3
2 changed files with 32 additions and 32 deletions

View File

@ -23,53 +23,53 @@ if it doesn't exist, with a random id.`,
}, },
} }
var addSource string var addItemSource string
var addId string var addItemId string
var addTitle string var addItemTitle string
var addAuthor string var addItemAuthor string
var addBody string var addItemBody string
var addLink string var addItemLink string
var addTime int var addItemTime int
func init() { func init() {
itemCmd.AddCommand(itemAddCmd) itemCmd.AddCommand(itemAddCmd)
itemAddCmd.Flags().StringVarP(&addSource, "source", "s", "", "Source in which to create the item (default: default)") itemAddCmd.Flags().StringVarP(&addItemSource, "source", "s", "", "Source in which to create the item (default: default)")
itemAddCmd.Flags().StringVarP(&addId, "id", "i", "", "Item id (default: random hex)") itemAddCmd.Flags().StringVarP(&addItemId, "id", "i", "", "Item id (default: random hex)")
itemAddCmd.Flags().StringVarP(&addTitle, "title", "t", "", "Item title") itemAddCmd.Flags().StringVarP(&addItemTitle, "title", "t", "", "Item title")
itemAddCmd.Flags().StringVarP(&addAuthor, "author", "a", "", "Item author") itemAddCmd.Flags().StringVarP(&addItemAuthor, "author", "a", "", "Item author")
itemAddCmd.Flags().StringVarP(&addBody, "body", "b", "", "Item body") itemAddCmd.Flags().StringVarP(&addItemBody, "body", "b", "", "Item body")
itemAddCmd.Flags().StringVarP(&addLink, "link", "l", "", "Item link") itemAddCmd.Flags().StringVarP(&addItemLink, "link", "l", "", "Item link")
itemAddCmd.Flags().IntVarP(&addTime, "time", "m", 0, "Item time as a Unix timestamp") itemAddCmd.Flags().IntVarP(&addItemTime, "time", "m", 0, "Item time as a Unix timestamp")
} }
func itemAdd() { func itemAdd() {
// Default to "default" source // Default to "default" source
if addSource == "" { if addItemSource == "" {
addSource = "default" addItemSource = "default"
} }
// Default id to random hex string // Default id to random hex string
if addId == "" { if addItemId == "" {
bytes := make([]byte, 16) bytes := make([]byte, 16)
if _, err := rand.Read(bytes); err != nil { if _, err := rand.Read(bytes); err != nil {
log.Fatal("Failed to generate id") log.Fatal("Failed to generate id")
} }
addId = hex.EncodeToString(bytes) addItemId = hex.EncodeToString(bytes)
} }
db := openAndMigrateDb() db := openAndMigrateDb()
if err := core.AddItems(db, []core.Item{{ if err := core.AddItems(db, []core.Item{{
Source: addSource, Source: addItemSource,
Id: addId, Id: addItemId,
Title: addTitle, Title: addItemTitle,
Author: addAuthor, Author: addItemAuthor,
Body: addBody, Body: addItemBody,
Link: addLink, Link: addItemLink,
Time: addTime, Time: addItemTime,
}}); err != nil { }}); err != nil {
log.Fatalf("Failed to add item: %s", err) log.Fatalf("Failed to add item: %s", err)
} }
fmt.Printf("Added %s/%s\n", addSource, addId) fmt.Printf("Added %s/%s\n", addItemSource, addItemId)
} }

View File

@ -25,20 +25,20 @@ var sourceTestCmd = &cobra.Command{
}, },
} }
var testEnv []string var sourceTestEnv []string
var testFormat string var sourceTestFormat string
func init() { func init() {
sourceCmd.AddCommand(sourceTestCmd) sourceCmd.AddCommand(sourceTestCmd)
sourceTestCmd.Flags().StringArrayVarP(&testEnv, "env", "e", nil, "Environment variables to set, in the form KEY=VAL") sourceTestCmd.Flags().StringArrayVarP(&sourceTestEnv, "env", "e", nil, "Environment variables to set, in the form KEY=VAL")
sourceTestCmd.Flags().StringVarP(&testFormat, "format", "f", "headlines", "Feed format for returned items.") sourceTestCmd.Flags().StringVarP(&sourceTestFormat, "format", "f", "headlines", "Feed format for returned items.")
} }
func sourceTest(cmd []string) { func sourceTest(cmd []string) {
formatter := formatAs(testFormat) formatter := formatAs(sourceTestFormat)
items, err := core.Execute("", cmd, testEnv, "", time.Minute) items, err := core.Execute("", cmd, sourceTestEnv, "", time.Minute)
log.Printf("Returned %d items", len(items)) log.Printf("Returned %d items", len(items))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)