Skip to content

Commit a0e84d4

Browse files
committed
add progress output
1 parent dc929cd commit a0e84d4

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ toolchain go1.24.2
66

77
require (
88
github.com/spf13/pflag v1.0.6
9+
golang.org/x/term v0.31.0
910
golift.io/version v0.0.2
10-
golift.io/xtractr v0.2.3-0.20250419170021-53bfe05970fe
11+
golift.io/xtractr v0.2.3-0.20250422011648-dfd640da4ba1
1112
)
1213

1314
require (
@@ -18,6 +19,7 @@ require (
1819
github.com/sshaman1101/dcompress v0.0.0-20200109162717-50436a6332de // indirect
1920
github.com/therootcompany/xz v1.0.1 // indirect
2021
golang.org/x/crypto v0.37.0 // indirect
22+
golang.org/x/sys v0.32.0 // indirect
2123
)
2224

2325
require (

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,13 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
209209
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
210210
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
211211
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
212+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
213+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
212214
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
213215
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
214216
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
217+
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
218+
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
215219
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
216220
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
217221
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -255,8 +259,8 @@ golift.io/cnfgfile v0.0.0-20240713024420-a5436d84eb48 h1:c7cJWRr0cUnFHKtq072esKz
255259
golift.io/cnfgfile v0.0.0-20240713024420-a5436d84eb48/go.mod h1:zHm9o8SkZ6Mm5DfGahsrEJPsogyR0qItP59s5lJ98/I=
256260
golift.io/version v0.0.2 h1:i0gXRuSDHKs4O0sVDUg4+vNIuOxYoXhaxspftu2FRTE=
257261
golift.io/version v0.0.2/go.mod h1:76aHNz8/Pm7CbuxIsDi97jABL5Zui3f2uZxDm4vB6hU=
258-
golift.io/xtractr v0.2.3-0.20250419170021-53bfe05970fe h1:fCqAf/BYLNy5BdX6IeeGIGutHqOANjIfKeYANd5Cktg=
259-
golift.io/xtractr v0.2.3-0.20250419170021-53bfe05970fe/go.mod h1:invEOYfyBnFtegY2V2n+9K5bUEHB8pGZng1BK0U2r38=
262+
golift.io/xtractr v0.2.3-0.20250422011648-dfd640da4ba1 h1:riqVi1hRC/d1LrP53qcYeKbsTOC7a6F9kkAFaDO3xW8=
263+
golift.io/xtractr v0.2.3-0.20250422011648-dfd640da4ba1/go.mod h1:invEOYfyBnFtegY2V2n+9K5bUEHB8pGZng1BK0U2r38=
260264
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
261265
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
262266
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func main() {
5757
pwd = "."
5858
}
5959

60+
log.SetOutput(os.Stdout)
61+
6062
// Get 1 job and other flag info from cli args.
6163
cliJob, flags := parseFlags(pwd)
6264
flags.printVer()

pkg/xt/job.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66

77
"golift.io/cnfgfile"
8+
"golift.io/xtractr"
89
)
910

1011
// Job defines the input data for one extraction run.
@@ -22,6 +23,7 @@ type Job struct {
2223
DebugLog bool `json:"debugLog" toml:"debug_log" xml:"debug_log" yaml:"debugLog"`
2324
Preserve bool `json:"preservePaths" toml:"preserve_paths" xml:"preserve_paths" yaml:"preservePaths"`
2425
Verbose bool `json:"verbose" toml:"verbose" xml:"verbose" yaml:"verbose"`
26+
progress chan xtractr.Progress
2527
}
2628

2729
// ParseJobs checks for and reads more jobs in from 0 or more job files.

pkg/xt/xt.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"golang.org/x/term"
1213
"golift.io/xtractr"
1314
)
1415

@@ -20,10 +21,11 @@ func Extract(job *Job) {
2021
}
2122

2223
job.fixModes()
24+
job.setupProgress()
2325

2426
total := archives.Count()
2527
count := 0
26-
size := int64(0)
28+
size := uint64(0)
2729
fCount := 0
2830
start := time.Now()
2931

@@ -54,14 +56,29 @@ func Extract(job *Job) {
5456
total, size, fCount, time.Since(start).Round(time.Millisecond))
5557
}
5658

57-
func (j *Job) processArchive(folder, archive string) (string, int64, []string, time.Duration, error) {
59+
func (j *Job) setupProgress() {
60+
every := float64(5)
61+
62+
isTerm := term.IsTerminal(int(os.Stdout.Fd()))
63+
if isTerm {
64+
every = 0.1
65+
}
66+
67+
if !j.DebugLog { // Only print progress if debug is off.
68+
j.progress = make(chan xtractr.Progress)
69+
go xtractr.ArchiveProgress(every, j.progress, term.IsTerminal(int(os.Stdout.Fd())), false)
70+
}
71+
}
72+
73+
func (j *Job) processArchive(folder, archive string) (string, uint64, []string, time.Duration, error) {
5874
file := &xtractr.XFile{
5975
FilePath: archive, // Path to archive being extracted.
6076
OutputDir: j.Output, // Folder to extract archive into.
6177
FileMode: j.FileMode.Mode(), // Write files with this mode.
6278
DirMode: j.DirMode.Mode(), // Write folders with this mode.
6379
Passwords: j.Passwords, // (RAR/7zip) Archive password(s).
6480
SquashRoot: j.SquashRoot, // Remove single root folder?
81+
Updates: j.progress,
6582
}
6683
file.SetLogger(j)
6784

0 commit comments

Comments
 (0)