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 addId string
var addTitle string
var addAuthor string
var addBody string
var addLink string
var addTime int
var addItemSource string
var addItemId string
var addItemTitle string
var addItemAuthor string
var addItemBody string
var addItemLink string
var addItemTime int
func init() {
itemCmd.AddCommand(itemAddCmd)
itemAddCmd.Flags().StringVarP(&addSource, "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(&addTitle, "title", "t", "", "Item title")
itemAddCmd.Flags().StringVarP(&addAuthor, "author", "a", "", "Item author")
itemAddCmd.Flags().StringVarP(&addBody, "body", "b", "", "Item body")
itemAddCmd.Flags().StringVarP(&addLink, "link", "l", "", "Item link")
itemAddCmd.Flags().IntVarP(&addTime, "time", "m", 0, "Item time as a Unix timestamp")
itemAddCmd.Flags().StringVarP(&addItemSource, "source", "s", "", "Source in which to create the item (default: default)")
itemAddCmd.Flags().StringVarP(&addItemId, "id", "i", "", "Item id (default: random hex)")
itemAddCmd.Flags().StringVarP(&addItemTitle, "title", "t", "", "Item title")
itemAddCmd.Flags().StringVarP(&addItemAuthor, "author", "a", "", "Item author")
itemAddCmd.Flags().StringVarP(&addItemBody, "body", "b", "", "Item body")
itemAddCmd.Flags().StringVarP(&addItemLink, "link", "l", "", "Item link")
itemAddCmd.Flags().IntVarP(&addItemTime, "time", "m", 0, "Item time as a Unix timestamp")
}
func itemAdd() {
// Default to "default" source
if addSource == "" {
addSource = "default"
if addItemSource == "" {
addItemSource = "default"
}
// Default id to random hex string
if addId == "" {
if addItemId == "" {
bytes := make([]byte, 16)
if _, err := rand.Read(bytes); err != nil {
log.Fatal("Failed to generate id")
}
addId = hex.EncodeToString(bytes)
addItemId = hex.EncodeToString(bytes)
}
db := openAndMigrateDb()
if err := core.AddItems(db, []core.Item{{
Source: addSource,
Id: addId,
Title: addTitle,
Author: addAuthor,
Body: addBody,
Link: addLink,
Time: addTime,
Source: addItemSource,
Id: addItemId,
Title: addItemTitle,
Author: addItemAuthor,
Body: addItemBody,
Link: addItemLink,
Time: addItemTime,
}}); err != nil {
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 testFormat string
var sourceTestEnv []string
var sourceTestFormat string
func init() {
sourceCmd.AddCommand(sourceTestCmd)
sourceTestCmd.Flags().StringArrayVarP(&testEnv, "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().StringArrayVarP(&sourceTestEnv, "env", "e", nil, "Environment variables to set, in the form KEY=VAL")
sourceTestCmd.Flags().StringVarP(&sourceTestFormat, "format", "f", "headlines", "Feed format for returned items.")
}
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))
if err != nil {
log.Fatal(err)