diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2fe7c01..c21ceca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go_version: ['1.21'] + go_version: ['1.22'] os: [ubuntu-latest, windows-latest, macos-latest] steps: diff --git a/cmd/root.go b/cmd/root.go index 05e1997..9701b95 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,6 +5,7 @@ import ( "os" "github.com/creativeprojects/catalogue/constants" + "github.com/pterm/pterm" "github.com/spf13/cobra" ) @@ -19,7 +20,9 @@ var ( Short: constants.Description, Long: `An offline file catalogue with fast search`, Run: func(cmd *cobra.Command, args []string) { - // set log level here + if rootFlags.Verbose { + pterm.EnableDebugMessages() + } }, } diff --git a/cmd/volume_add.go b/cmd/volume_add.go index dc852d2..961ae05 100644 --- a/cmd/volume_add.go +++ b/cmd/volume_add.go @@ -4,6 +4,8 @@ import ( "fmt" "os" "strings" + "sync" + "time" "github.com/creativeprojects/catalogue/index" "github.com/creativeprojects/catalogue/volume" @@ -40,10 +42,30 @@ var volumeAddCmd = &cobra.Command{ return } volume.PrintVolume(vol) + fmt.Println("") - progresser := index.NewProgress(&pterm.DefaultSpinner) - indexer := index.NewIndexer(volumePath) - indexer.Run(progresser) + wg := new(sync.WaitGroup) + fileIndexedChannel := make(chan index.FileIndexed, 1000) + wg.Add(1) + go func() { + defer wg.Done() + start := time.Now() + progresser := index.NewProgress() + progresser.Start() + + for fileIndexed := range fileIndexedChannel { + if fileIndexed.Error != nil { + progresser.Error(fileIndexed.Path, fileIndexed.Error) + continue + } + progresser.Increment(fileIndexed.Path, fileIndexed.Info) + } + progresser.Success("Indexing complete in " + time.Since(start).String()) + }() + indexer := index.NewIndexer(volumePath, fileIndexedChannel) + indexer.Run() + close(fileIndexedChannel) + wg.Wait() }, } diff --git a/go.mod b/go.mod index 4e986b0..09c5a2c 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,15 @@ module github.com/creativeprojects/catalogue -go 1.21 +go 1.22 require ( - github.com/google/uuid v1.4.0 - github.com/pterm/pterm v0.12.72 + github.com/google/uuid v1.6.0 + github.com/pterm/pterm v0.12.79 github.com/spf13/afero v1.11.0 github.com/spf13/cobra v1.8.0 - github.com/stretchr/testify v1.8.4 - go.etcd.io/bbolt v1.3.8 - golang.org/x/sys v0.15.0 + github.com/stretchr/testify v1.9.0 + go.etcd.io/bbolt v1.3.10 + golang.org/x/sys v0.21.0 howett.net/plist v1.0.1 ) @@ -28,7 +28,7 @@ require ( github.com/rivo/uniseg v0.4.4 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - golang.org/x/term v0.15.0 // indirect + golang.org/x/term v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8e2dc84..db6a5bf 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= @@ -56,8 +56,8 @@ github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEej github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE= github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8= github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= -github.com/pterm/pterm v0.12.72 h1:1W7Oqi5yjEvrI0QroBqUefqXKJW4aD8/wAuqqd5qj0Q= -github.com/pterm/pterm v0.12.72/go.mod h1:+M33aZWQVpmLmLbvjykyGZ4gAfeebznRo8JMbabaxQU= +github.com/pterm/pterm v0.12.79 h1:lH3yrYMhdpeqX9y5Ep1u7DejyHy7NSQg9qrBjF9dFT4= +github.com/pterm/pterm v0.12.79/go.mod h1:1v/gzOF1N0FsjbgTHZ1wVycRkKiatFvJSJC4IGaQAAo= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -74,14 +74,14 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= -go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= +go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= +go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= @@ -95,6 +95,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -105,15 +107,15 @@ golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= +golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= diff --git a/index/index.go b/index/index.go index dec8adc..42e5eaf 100644 --- a/index/index.go +++ b/index/index.go @@ -4,55 +4,60 @@ import ( "os" "path/filepath" - "github.com/pterm/pterm" "github.com/spf13/afero" ) +type FileIndexed struct { + Path string + Info os.FileInfo + Error error +} + type Indexer struct { - fs afero.Fs - rootPath string - progressBar *pterm.ProgressbarPrinter + fs afero.Fs + rootPath string + fileIndexedChannel chan<- FileIndexed } -func NewIndexer(rootPath string) *Indexer { - return NewFsIndexer(rootPath, afero.NewOsFs()) +func NewIndexer(rootPath string, fileIndexedChannel chan<- FileIndexed) *Indexer { + return NewFsIndexer(rootPath, fileIndexedChannel, afero.NewOsFs()) } -func NewFsIndexer(rootPath string, fs afero.Fs) *Indexer { - pbar, _ := pterm.DefaultProgressbar.WithShowElapsedTime().WithShowCount().WithShowTitle().Start() +func NewFsIndexer(rootPath string, fileIndexedChannel chan<- FileIndexed, fs afero.Fs) *Indexer { return &Indexer{ - fs: fs, - rootPath: rootPath, - progressBar: pbar, + fs: fs, + rootPath: rootPath, + fileIndexedChannel: fileIndexedChannel, } } -func (i *Indexer) Run(progresser Progresser) { +// Run starts the indexing process. It will walk the filesystem and send the results to the fileIndexedChannel. +// The Run method will return after all files have been indexed. +func (i *Indexer) Run() { _ = i.walk(i.rootPath) } func (i *Indexer) walk(path string) error { file, err := i.fs.Open(path) if err != nil { - pterm.Error.Printf("%s: %s\n", path, err) + i.fileIndexedChannel <- FileIndexed{Path: path, Error: err} return err } names, err := file.Readdirnames(-1) file.Close() if err != nil { - pterm.Error.Printf("%s: %s\n", path, err) + i.fileIndexedChannel <- FileIndexed{Path: path, Error: err} return err } - i.progressBar.Total += len(names) for _, name := range names { - i.progressBar.Increment() filename := filepath.Join(path, name) fileInfo, err := lstatIfPossible(i.fs, filename) if err != nil { - pterm.Error.Printf("%s: %s\n", filename, err) + i.fileIndexedChannel <- FileIndexed{Path: filename, Error: err} continue } + i.fileIndexedChannel <- FileIndexed{Path: filename, Info: fileInfo} if fileInfo.IsDir() { _ = i.walk(filename) } diff --git a/index/progress.go b/index/progress.go index 07d009f..1a429bd 100644 --- a/index/progress.go +++ b/index/progress.go @@ -1,50 +1,58 @@ package index import ( + "fmt" "os" - "strings" + "github.com/creativeprojects/catalogue/ui" "github.com/pterm/pterm" ) type Progresser interface { - Increment(path string, info os.FileInfo, fileCount, dirCount int) + Start() + Increment(path string, info os.FileInfo) Error(path string, err error) Success(message string) } type Progress struct { - spinner *pterm.SpinnerPrinter + spinner *ui.SpinnerPrinter + fileCount int + dirCount int + errorCount int } -func NewProgress(spinner *pterm.SpinnerPrinter) *Progress { - if spinner == nil { - spinner = &pterm.DefaultSpinner - } - spinner.Start() +func NewProgress() *Progress { return &Progress{ - spinner: spinner, + spinner: ui.DefaultSpinner, } } -func (p *Progress) Increment(path string, info os.FileInfo, fileCount, dirCount int) { - maxWidth := pterm.GetTerminalWidth() - 5 - display := path - if len(display) > maxWidth { - display = display[len(display)-maxWidth:] - } - if len(display) < maxWidth { // pad with spaces - display = display + strings.Repeat(" ", maxWidth-len(display)) +func (p *Progress) Start() { + p.spinner.Start() +} + +func (p *Progress) Increment(path string, info os.FileInfo) { + if info.IsDir() { + p.dirCount++ + } else { + p.fileCount++ } - p.spinner.Text = display - p.spinner.WithText(display) + p.update() } func (p *Progress) Error(path string, err error) { - p.spinner.FailPrinter.Printf("%s: %s\n", path, err) + pterm.Error.Println("\r", err) + p.errorCount++ + p.update() } func (p *Progress) Success(message string) { - p.spinner.Success(message) - _ = p.spinner.Stop() + p.spinner.Stop() + pterm.Success.Println(message) +} + +func (p *Progress) update() { + text := fmt.Sprintf("Files: %d, Directories: %d, Errors: %d", p.fileCount, p.dirCount, p.errorCount) + p.spinner.UpdateText(text) } diff --git a/store/bucket_test.go b/store/bucket_test.go index 084e90f..866068f 100644 --- a/store/bucket_test.go +++ b/store/bucket_test.go @@ -1,9 +1,7 @@ package store import ( - "math/rand" "testing" - "time" "github.com/stretchr/testify/assert" ) @@ -13,10 +11,6 @@ type testBucketData struct { bucket Bucket } -func init() { - rand.Seed(time.Now().UnixNano()) -} - func getBuckets() []testBucketData { data := make([]testBucketData, 1) @@ -25,6 +19,8 @@ func getBuckets() []testBucketData { } func TestLoadingUnknownKeyFromBucket(t *testing.T) { + t.Parallel() + for _, data := range getBuckets() { t.Run(data.name, func(t *testing.T) { _, err := data.bucket.GetKey("some-key") @@ -34,8 +30,12 @@ func TestLoadingUnknownKeyFromBucket(t *testing.T) { } func TestSetKeyAndGetKeyFromBucket(t *testing.T) { + t.Parallel() + for _, data := range getBuckets() { t.Run(data.name, func(t *testing.T) { + t.Parallel() + var err error var value1, value2 []byte diff --git a/store/memory_store.go b/store/memory_store.go index e982992..4e286b0 100644 --- a/store/memory_store.go +++ b/store/memory_store.go @@ -25,11 +25,11 @@ func NewMemoryStore() *MemoryStore { } // Begin a transaction -func (s *MemoryStore) Begin(writable bool) (Transaction, error) { - return s.begin(writable) +func (s *MemoryStore) Begin(writeable bool) (Transaction, error) { + return s.begin(writeable) } -func (s *MemoryStore) begin(writable bool) (*MemoryTransaction, error) { +func (s *MemoryStore) begin(writeable bool) (*MemoryTransaction, error) { s.transactionsMutex.Lock() defer s.transactionsMutex.Unlock() @@ -48,8 +48,8 @@ func (s *MemoryStore) begin(writable bool) (*MemoryTransaction, error) { remove() } - if writable { - // Have a full lock on writable buckets + if writeable { + // Have a full lock on writeable buckets s.writeMutex.Lock() // Unlock at the end @@ -59,7 +59,7 @@ func (s *MemoryStore) begin(writable bool) (*MemoryTransaction, error) { } } - tx := newMemoryTransaction(s, writable, close) + tx := newMemoryTransaction(s, writeable, close) s.transactions[transactionID] = tx return tx, nil } diff --git a/ui/spinner.go b/ui/spinner.go new file mode 100644 index 0000000..040899a --- /dev/null +++ b/ui/spinner.go @@ -0,0 +1,89 @@ +package ui + +import ( + "io" + "strings" + "sync/atomic" + "time" + + "github.com/pterm/pterm" +) + +// DefaultSpinner is the default SpinnerPrinter. +var DefaultSpinner = &SpinnerPrinter{ + Sequence: []string{"▀ ", " ▀", " ▄", "▄ "}, + Style: &pterm.ThemeDefault.SpinnerStyle, + Delay: time.Millisecond * 200, + ShowTimer: true, + TimerRoundingFactor: time.Second, + TimerStyle: &pterm.ThemeDefault.TimerStyle, + MessageStyle: &pterm.ThemeDefault.SpinnerTextStyle, +} + +// SpinnerPrinter is a loading animation, which can be used if the progress is unknown. +type SpinnerPrinter struct { + text atomic.Pointer[string] + Sequence []string + Style *pterm.Style + Delay time.Duration + MessageStyle *pterm.Style + ShowTimer bool + TimerRoundingFactor time.Duration + TimerStyle *pterm.Style + + IsActive bool + + startedAt time.Time + currentSequence string + + Writer io.Writer +} + +// UpdateText updates the message of the active SpinnerPrinter. +func (s *SpinnerPrinter) UpdateText(text string) { + s.text.Store(&text) +} + +func (s *SpinnerPrinter) Text() string { + pointer := s.text.Load() + if pointer == nil { + return "" + } + return *pointer +} + +// Start the SpinnerPrinter. +func (s *SpinnerPrinter) Start() *SpinnerPrinter { + s.IsActive = true + s.startedAt = time.Now() + + go func() { + for s.IsActive { + for _, seq := range s.Sequence { + if !s.IsActive { + continue + } + + var timer string + if s.ShowTimer { + timer = " (" + time.Since(s.startedAt).Round(s.TimerRoundingFactor).String() + ")" + } + pterm.Fprinto(s.Writer, s.Style.Sprint(seq)+" "+s.MessageStyle.Sprint(s.Text())+s.TimerStyle.Sprint(timer)) + s.currentSequence = seq + time.Sleep(s.Delay) + } + } + }() + return s +} + +// Stop terminates the SpinnerPrinter immediately. +// The SpinnerPrinter will not resolve into anything. +func (s *SpinnerPrinter) Stop() { + if !s.IsActive { + return + } + s.IsActive = false + pterm.Fprinto(s.Writer, strings.Repeat(" ", pterm.GetTerminalWidth())) + pterm.Fprinto(s.Writer) +} diff --git a/volume/volume.go b/volume/volume.go index a1fb644..fc96239 100644 --- a/volume/volume.go +++ b/volume/volume.go @@ -27,6 +27,7 @@ type Volume struct { Hostname string IncludeInSearch bool Location string + Connection string } // NewVolumeFromPath creates a populates Volume data from volumePath @@ -61,6 +62,7 @@ func PrintVolume(volume *Volume) { fmt.Printf(" Hostname: %s\n", volume.Hostname) fmt.Printf(" Created: %s\n", volume.Created) fmt.Printf(" Name: %s\n", volume.Name) + fmt.Printf(" Connection: %s\n", volume.Connection) fmt.Printf(" ID: %s\n", volume.VolumeID) fmt.Printf(" Device: %s\n", volume.Device) fmt.Printf(" Type: %s\n", volume.VolumeType.String()) diff --git a/volume/volume_darwin.go b/volume/volume_darwin.go index 16d607e..ba76e3f 100644 --- a/volume/volume_darwin.go +++ b/volume/volume_darwin.go @@ -94,6 +94,7 @@ func getDriveInfo(partition string, vol *Volume) error { vol.Name = data.VolumeName vol.VolumeID = data.VolumeUUID + vol.Connection = data.BusProtocol if data.Removable { vol.VolumeType = DriveRemovable @@ -106,8 +107,6 @@ func getDriveInfo(partition string, vol *Volume) error { vol.VolumeType = DriveRemovable } - // Debug - fmt.Printf("\n%+v\n", data) return nil } diff --git a/volume/volume_test.go b/volume/volume_test.go index 88b3843..e1e877d 100644 --- a/volume/volume_test.go +++ b/volume/volume_test.go @@ -9,6 +9,8 @@ import ( ) func TestCanGetVolumeInformation(t *testing.T) { + t.Parallel() + cwd, err := os.Getwd() require.NoError(t, err)