Esempio n. 1
0
func PrintStoreCommand() common.Command {
	var (
		tasks   bool
		lrps    bool
		verbose bool
	)

	flagSet := flag.NewFlagSet("print-store", flag.ExitOnError)
	flagSet.BoolVar(&verbose, "v", false, "be verbose")
	flagSet.BoolVar(&tasks, "tasks", true, "print tasks")
	flagSet.BoolVar(&lrps, "lrps", true, "print lrps")

	return common.Command{
		Name:        "print-store",
		Description: "[file] - Print previously fetched contents of the BBS.  If file is blank, reads from stdin.",
		FlagSet:     flagSet,
		Run: func(args []string) {
			if len(args) == 0 {
				err := print_store.PrintStore(verbose, tasks, lrps, false, os.Stdin)
				common.ExitIfError("Failed to print store", err)
			} else {
				f, err := os.Open(args[0])
				common.ExitIfError("Could not open file", err)

				err = print_store.PrintStore(verbose, tasks, lrps, false, f)
				common.ExitIfError("Failed to print store", err)
			}
		},
	}
}
Esempio n. 2
0
func dump(bbsClient bbs.Client, verbose bool, tasks bool, lrps bool, clear bool) error {
	reader, writer := io.Pipe()

	errs := make(chan error)
	go func() {
		err := fetch_store.Fetch(bbsClient, writer)
		errs <- err
	}()
	go func() {
		err := print_store.PrintStore(verbose, tasks, lrps, clear, reader)
		errs <- err
	}()

	err1 := <-errs
	if err1 != nil {
		return err1
	}
	err2 := <-errs
	if err2 != nil {
		return err2
	}
	return nil
}