From 73d92ec8284afdce4fdf05e5f1f42accbbf93264 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 6 Feb 2022 01:22:11 +0100 Subject: [PATCH] refactor: merge UI for serving/generating See https://git.vvvvvvaria.org/decentral1se/distribusi-go/issues/8 --- distribusi.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/distribusi.go b/distribusi.go index ddff375..acf7892 100644 --- a/distribusi.go +++ b/distribusi.go @@ -340,7 +340,7 @@ Example: func distribusify(c *cli.Context, root string, ignore []string) error { var allDirs []string - progress := mkProgressBar() + progress := mkProgressBar(c) if err := filepath.Walk(root, func(fpath string, finfo os.FileInfo, err error) error { @@ -782,8 +782,6 @@ func serveHTTP(fpath string) error { fs := http.FileServer(http.Dir(fpath)) http.Handle("/", fs) - logrus.Infof("distribusi serving from http://localhost%s", port) - if err := http.ListenAndServe(port, nil); err != nil { return err } @@ -859,9 +857,16 @@ func getLogFile() (*os.File, error) { // mkProgressBar creates a customised progress bar. This bar is used to give // real-time updates on the progress of running distribusi. -func mkProgressBar() *progressbar.ProgressBar { +func mkProgressBar(c *cli.Context) *progressbar.ProgressBar { + var description string + if c.Bool("serve") { + description = fmt.Sprintf("distribusifying... live @ http://localhost%s", port) + } else { + description = "distribusifying..." + } + bar := progressbar.NewOptions(-1, - progressbar.OptionSetDescription("distribusifying..."), + progressbar.OptionSetDescription(description), progressbar.OptionSetWriter(ansi.NewAnsiStdout()), progressbar.OptionEnableColorCodes(true), progressbar.OptionShowCount(),