Add date/time flag to command and update functions

This commit is contained in:
Dan Jones 2026-03-01 08:52:59 -06:00
commit 21d27f8068
5 changed files with 13 additions and 10 deletions

View file

@ -27,6 +27,7 @@ import (
) )
var outJson bool var outJson bool
var d mycli.Date
// YtDropCmd represents the drop command // YtDropCmd represents the drop command
var YtDropCmd = &cobra.Command{ var YtDropCmd = &cobra.Command{
@ -41,7 +42,7 @@ var YtDropCmd = &cobra.Command{
} }
url := args[0] url := args[0]
log, err := ytdlp.Drop(cmd.Context(), url) log, err := ytdlp.Drop(cmd.Context(), url, d.Time())
if err != nil { if err != nil {
return err return err
} }
@ -64,6 +65,8 @@ var YtDropCmd = &cobra.Command{
} }
func init() { func init() {
(&d).Set("now")
mycli.RootCmd.AddCommand(YtDropCmd) mycli.RootCmd.AddCommand(YtDropCmd)
YtDropCmd.Flags().VarP(&d, "date", "d", "Date for log entry")
YtDropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON") YtDropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON")
} }

4
go.mod
View file

@ -3,8 +3,9 @@ module my-log-wynter
go 1.26.0 go 1.26.0
require ( require (
codeberg.org/danjones000/my-log v0.1.0 codeberg.org/danjones000/my-log v0.1.1
github.com/lrstanley/go-ytdlp v1.3.1 github.com/lrstanley/go-ytdlp v1.3.1
github.com/spf13/cobra v1.8.0
) )
require ( require (
@ -21,7 +22,6 @@ require (
github.com/magefile/mage v1.14.0 // indirect github.com/magefile/mage v1.14.0 // indirect
github.com/markusmobius/go-dateparser v1.2.3 // indirect github.com/markusmobius/go-dateparser v1.2.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/tetratelabs/wazero v1.2.1 // indirect github.com/tetratelabs/wazero v1.2.1 // indirect
github.com/ulikunitz/xz v0.5.15 // indirect github.com/ulikunitz/xz v0.5.15 // indirect

4
go.sum
View file

@ -1,5 +1,5 @@
codeberg.org/danjones000/my-log v0.1.0 h1:HJYCZ8rYpOtVpU1927M1H1FjbB/6acwrV8eJ4TUDHac= codeberg.org/danjones000/my-log v0.1.1 h1:+hafzvJI/IK0SnNjeX+pnrlarDpT2+pJ5tVY0yphSUo=
codeberg.org/danjones000/my-log v0.1.0/go.mod h1:XxiJfEyCKDeHzCNUeULL02zDXwsU2WHXfoBPNboYHYU= codeberg.org/danjones000/my-log v0.1.1/go.mod h1:XxiJfEyCKDeHzCNUeULL02zDXwsU2WHXfoBPNboYHYU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw= github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=

View file

@ -2,21 +2,21 @@ package ytdlp
import ( import (
"context" "context"
"time"
"codeberg.org/danjones000/my-log/files" "codeberg.org/danjones000/my-log/files"
"codeberg.org/danjones000/my-log/models" "codeberg.org/danjones000/my-log/models"
ytd "github.com/lrstanley/go-ytdlp"
) )
// Drop adds the URL specified by the url to the watched log. // Drop adds the URL specified by the url to the watched log.
func Drop(ctx context.Context, url string) (models.Log, error) { func Drop(ctx context.Context, url string, now time.Time) (models.Log, error) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return models.Log{}, context.Cause(ctx) return models.Log{}, context.Cause(ctx)
default: default:
} }
log, err := GetLog(ctx, url) log, err := GetLog(ctx, url, now)
if err != nil { if err != nil {
return log, err return log, err
} }

View file

@ -30,7 +30,7 @@ func Fetch(ctx context.Context, url string) (*ytd.ExtractedInfo, error) {
return infos[0], nil return infos[0], nil
} }
func GetLog(ctx context.Context, url string) (models.Log, error) { func GetLog(ctx context.Context, url string, now time.Time) (models.Log, error) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return models.Log{}, context.Cause(ctx) return models.Log{}, context.Cause(ctx)
@ -42,8 +42,8 @@ func GetLog(ctx context.Context, url string) (models.Log, error) {
if err != nil { if err != nil {
return models.Log{}, err return models.Log{}, err
} }
now := time.Now()
ent.Date = now ent.Date = now
// TODO Get published date
metas := &ent.Fields metas := &ent.Fields
*metas = metas.Set("id", getID(now, info)) *metas = metas.Set("id", getID(now, info))