Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Expand quiet support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Jun 12, 2022
1 parent 1ec476d commit fb94aaf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
9 changes: 7 additions & 2 deletions pkg/cmd/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ var apisCmd = &cobra.Command{
Long: `Run batch data synchronizations with the remote APIs hosted
on demozoo.org and pouet.net. All these commands are SLOW and
require the parsing of 10,000s of records.`,
Aliases: []string{"ap", "api"},
Aliases: []string{"api"},
Example: ` df2 apis [--refresh|--pouet|--msdos|--windows]`,
Run: func(cmd *cobra.Command, args []string) {
err := run.Apis(apis)
quiet := false
q := rootCmd.PersistentFlags().Lookup("quiet")
if q.Value.String() == "true" {
quiet = true
}
err := run.Apis(apis, quiet)
switch {
case errors.Is(err, run.ErrArgFlag):
if err := cmd.Usage(); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/demozoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ There are additional Demozoo commands found under the api command.`,
Example: ` df2 demozoo [--new|--all|--releases|--id] (--dry-run,--overwrite)
df2 demozoo [--ping|--download]`,
Run: func(cmd *cobra.Command, args []string) {
err := run.Demozoo(dzf)
quiet := false
q := rootCmd.PersistentFlags().Lookup("quiet")
if q.Value.String() == "true" {
quiet = true
}
err := run.Demozoo(dzf, quiet)
switch {
case errors.Is(err, run.ErrDZFlag):
if err := cmd.Usage(); err != nil {
Expand Down
27 changes: 16 additions & 11 deletions pkg/cmd/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Data(dbf database.Flags) error {
return nil
}

func Apis(a arg.Apis) error {
func Apis(a arg.Apis, quiet bool) error {
switch {
case a.Refresh:
if err := demozoo.RefreshMeta(); err != nil {
Expand All @@ -80,27 +80,26 @@ func Apis(a arg.Apis) error {
return err
}
case a.SyncDos:
if err := syncdos(); err != nil {
if err := syncdos(quiet); err != nil {
return err
}
case a.SyncWin:
if err := syncwin(); err != nil {
if err := syncwin(quiet); err != nil {
return err
}
default:
return ErrDZFlag
return ErrArgFlag
}
return nil
}

func Demozoo(dzf arg.Demozoo) error {
func Demozoo(dzf arg.Demozoo, quiet bool) error {
var empty []string
// TODO: apply these to --sync, --releases, etc
// TODO: apply --quiet to this Request
r := demozoo.Request{
All: dzf.All,
Overwrite: dzf.Overwrite,
Simulate: dzf.Simulate,
Quiet: quiet,
}
switch {
case dzf.New, dzf.All:
Expand Down Expand Up @@ -139,21 +138,27 @@ func Demozoo(dzf arg.Demozoo) error {
return nil
}

func syncdos() error {
func syncdos(quiet bool) error {
var p demozoo.MsDosProducts
p.Quiet = quiet
if err := p.Get(); err != nil {
return err
}
fmt.Printf("There were %d new productions found\n", p.Finds)
if !quiet {
fmt.Printf("There were %d new productions found\n", p.Finds)
}
return nil
}

func syncwin() error {
func syncwin(quiet bool) error {
var p demozoo.WindowsProducts
p.Quiet = quiet
if err := p.Get(); err != nil {
return err
}
fmt.Printf("There were %d new productions found\n", p.Finds)
if !quiet {
fmt.Printf("There were %d new productions found\n", p.Finds)
}
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/demozoo/demozoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ type MsDosProducts struct {
API []releases.ProductionV1
Count int
Finds int
Quiet bool
}

func (m *MsDosProducts) Get() error {
d := filter.Productions{Filter: releases.MsDos}
api, err := d.Prods(false)
api, err := d.Prods(m.Quiet)
if err != nil {
return fmt.Errorf("get msdos prods: %w", err)
}
Expand All @@ -106,11 +107,12 @@ type WindowsProducts struct {
API []releases.ProductionV1
Count int
Finds int
Quiet bool
}

func (m *WindowsProducts) Get() error {
d := filter.Productions{Filter: releases.Windows}
api, err := d.Prods(false)
api, err := d.Prods(m.Quiet)
if err != nil {
return fmt.Errorf("get msdos prods: %w", err)
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/demozoo/internal/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ func (p *Productions) Prods(quiet bool) ([]releases.ProductionV1, error) {
if err != nil {
return empty(), err
}
req := download.Request{
Link: url,
}
req := download.Request{Link: url}
if !quiet {
fmt.Printf("Fetching the first 100 of many records from Demozoo\n")
}
Expand Down Expand Up @@ -111,9 +109,7 @@ func pp(page, finds int) {

// Next gets all the next page of productions.
func Next(url string) ([]releases.ProductionV1, string, error) {
req := download.Request{
Link: url,
}
req := download.Request{Link: url}
if err := req.Body(); err != nil {
return empty(), "", fmt.Errorf("filter data body: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/demozoo/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Request struct {
Refresh bool // Refresh all demozoo entries.
Simulate bool // Simulate database save.
ByID string // Filter by ID.
Quiet bool
}

// Query parses a single Demozoo entry.
Expand Down

0 comments on commit fb94aaf

Please sign in to comment.