refactor: merge UI for serving/generating

See https://git.vvvvvvaria.org/decentral1se/distribusi-go/issues/8
This commit is contained in:
decentral1se 2022-02-06 01:22:11 +01:00
parent 57ff749cdb
commit 73d92ec828
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 10 additions and 5 deletions

View File

@ -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(),