-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cmdline
-c
& optimize log printing
- Loading branch information
Showing
5 changed files
with
116 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
errZeroMeterSize = errors.New("zero meter size") | ||
) | ||
|
||
type progressmeter struct { | ||
prefix string | ||
name string | ||
size int | ||
prgs int | ||
lstp int | ||
io.Writer | ||
} | ||
|
||
func newmeter(prefix, name string, size int) (pm progressmeter) { | ||
pm.prefix = prefix | ||
pm.name = name | ||
pm.size = size | ||
return | ||
} | ||
|
||
func (pm *progressmeter) Write(p []byte) (n int, err error) { | ||
if pm.size == 0 { | ||
return 0, errZeroMeterSize | ||
} | ||
pm.prgs += len(p) | ||
percent := pm.prgs * 100 / pm.size | ||
if percent == pm.lstp { | ||
return len(p), nil | ||
} | ||
logrus.Infof("%s [%2d%%] %s\t(%d/%dMB)", pm.prefix, percent, pm.name, pm.prgs/1024/1024, pm.size/1024/1024) | ||
pm.lstp = percent | ||
return len(p), nil | ||
} |