Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions cmd/test copy.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package cmd

import (
"rioctl/internal/ui"
// var test2CMD = &cobra.Command{
// Use: "test2",
// Short: "test operations",
// Args: cobra.ArbitraryArgs,
// RunE: func(cmd *cobra.Command, args []string) error {

"github.com/spf13/cobra"
)
// allFiles := []string{"asdf", "asdf"}
// _, err := ui.RunFilePicker(allFiles)
// return err
// },
// }

var test2CMD = &cobra.Command{
Use: "test2",
Short: "test operations",
Args: cobra.ArbitraryArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// func init() {

allFiles := []string{"asdf", "asdf"}
_, err := ui.RunFilePicker(allFiles)
return err
},
}

func init() {

rootCmd.AddCommand(test2CMD)
}
// rootCmd.AddCommand(test2CMD)
// }
17 changes: 10 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ module rioctl
go 1.26.1

require (
charm.land/bubbles/v2 v2.1.0 // indirect
charm.land/bubbletea/v2 v2.0.2 // indirect
charm.land/lipgloss/v2 v2.0.2 // indirect
charm.land/bubbles/v2 v2.1.0
charm.land/bubbletea/v2 v2.0.2
charm.land/lipgloss/v2 v2.0.2
github.com/charmbracelet/bubbles v1.0.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/melbahja/goph v1.5.0
github.com/spf13/cobra v1.10.2
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/bubbles v1.0.0 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.4.2 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
Expand All @@ -29,15 +34,13 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.21 // indirect
github.com/melbahja/goph v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.10 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.49.0 // indirect
Expand Down
13 changes: 8 additions & 5 deletions internal/sshclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package sshclient

import (
"fmt"
"rioctl/internal/utils"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -36,22 +38,23 @@ func (c *Client) Close() error {
return c.client.Close()
}

func (c *Client) ListFiles(dir string) ([]string, error) {
out, err := c.Run(fmt.Sprintf("find %s -type f -name '*.wpilog'", dir))
func (c *Client) ListFiles(dir string) ([]utils.File, error) {
out, err := c.Run(fmt.Sprintf("ls -lh %s | grep .wpilog | awk '{ print $5\",\"$9 }'", dir))
if err != nil {
return nil, err
}

lines := strings.Split(out, "\n")

var files []string
var files []utils.File
for _, l := range lines {
if l == "" {
continue
}
files = append(files, strings.TrimPrefix(l, dir+"/"))
stringArr := strings.Split(l, ",")
files = append(files, utils.File{Name: stringArr[1], Size: stringArr[0]})
}

slices.Reverse(files)
return files, nil
}

Expand Down
13 changes: 6 additions & 7 deletions internal/transfer/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@

func PullFiles(client *sshclient.Client, remoteBase, localBase string, files []string) error {
finishedChan := make(chan int)
currentChan := make(chan utils.File)
currentChan := make(chan utils.FileUpload)

go func() {
for i, file := range files {
remotePath := filepath.Join(remoteBase, file)
remotePath := filepath.ToSlash(filepath.Join(remoteBase, file))
localPath := filepath.Join(localBase, file)

if err := os.MkdirAll(filepath.Dir(localPath), 0755); err != nil {

Check failure on line 22 in internal/transfer/scp.go

View workflow job for this annotation

GitHub Actions / lint

SA9003: empty branch (staticcheck)
// continue
// fmt.Print(err)
}

err := os.Remove(localPath)
if err != nil {

Check failure on line 27 in internal/transfer/scp.go

View workflow job for this annotation

GitHub Actions / lint

SA9003: empty branch (staticcheck)
//
// fmt.Print(err)
}
totalSize, err := client.FileSize(remotePath)
if err != nil {

Check failure on line 31 in internal/transfer/scp.go

View workflow job for this annotation

GitHub Actions / lint

SA9003: empty branch (staticcheck)
//
// fmt.Print(err)
}
file := utils.NewFile(totalSize, 0, file)
currentChan <- file
Expand All @@ -50,8 +50,7 @@
// goph SCP download
err = client.Raw().Download(remotePath, localPath)
if err != nil {
// fmt.Printf("failed to download %s: %w", file, err)
// continue
// fmt.Print(err)
}

finishedChan <- i + 1
Expand Down
32 changes: 14 additions & 18 deletions internal/ui/filepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ui
import (
"fmt"
"os"
"rioctl/internal/utils"

"charm.land/bubbles/v2/list"
tea "charm.land/bubbletea/v2"
Expand All @@ -15,6 +16,7 @@ var defaultDelegate = list.NewDefaultDelegate()

type item struct {
title string
size string
selected bool
}

Expand All @@ -26,18 +28,14 @@ func (i item) Title() string {
// return i.title
}
func (i item) Description() string {
// if i.selected {
// return "[x]"
// }
// return "[ ]"
return ""
return " " + i.size
}

func (i item) FilterValue() string { return i.title }

type model struct {
list list.Model
choices []item
choices []*item
quitting bool
}

Expand All @@ -58,6 +56,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case "ctrl+c", "q":
m.quitting = true
m.choices = []*item{}
return m, tea.Quit

case "enter":
Expand All @@ -68,18 +67,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case "space":
i := m.list.Index()
m.choices[i].selected = !m.choices[i].selected
f, ok := m.list.SelectedItem().(*item)
if ok {
f.selected = !f.selected
}
}
case tea.WindowSizeMsg:
h, v := docStyle.GetFrameSize()
m.list.SetSize(msg.Width-h, msg.Height-v)
}
interfaces := make([]list.Item, len(m.choices))
for i, v := range m.choices {
interfaces[i] = v
}
m.list.SetItems(interfaces)
var cmd tea.Cmd
m.list, cmd = m.list.Update(msg)
return m, cmd
Expand All @@ -102,17 +98,17 @@ func (m model) Selected() []string {
return out
}

func NewFilePicker(files []string) model {
func NewFilePicker(files []utils.File) model {
items := make([]list.Item, len(files))
choices := make([]item, len(files))
choices := make([]*item, len(files))

for i, f := range files {
it := item{title: f}
it := &item{title: f.Name, size: f.Size}
items[i] = it
choices[i] = it
}

defaultDelegate.ShowDescription = false
// defaultDelegate.ShowDescription = false
l := list.New(items, defaultDelegate, 0, 0)
l.Title = "Select log files (space to toggle, enter to confirm)"

Expand All @@ -122,7 +118,7 @@ func NewFilePicker(files []string) model {
}
}

func RunFilePicker(files []string) ([]string, error) {
func RunFilePicker(files []utils.File) ([]string, error) {
m := NewFilePicker(files)

p := tea.NewProgram(m)
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
m.done = true
return m, tea.Quit
}
case utils.File:
case utils.FileUpload:
m.currentFileBytes = msg.Current
m.totalFileBytes = msg.Size
m.currentFile = msg.Name
Expand Down Expand Up @@ -94,7 +94,7 @@
pad + helpStyle(fmt.Sprintf("%s / %s", humanize(m.currentFileBytes), humanize((m.totalFileBytes)))))
}

func RunProgress(total int, current <-chan utils.File, finished <-chan int) {
func RunProgress(total int, current <-chan utils.FileUpload, finished <-chan int) {
m := NewProgress(total)
p := tea.NewProgram(m)

Expand All @@ -109,7 +109,7 @@
}
}()

p.Run()

Check failure on line 112 in internal/ui/progress.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `p.Run` is not checked (errcheck)
}

func RunProgress1(total int, stuff []string) {
Expand All @@ -122,7 +122,7 @@
}
}()

p.Run()

Check failure on line 125 in internal/ui/progress.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `p.Run` is not checked (errcheck)
}

func humanize(b int64) string {
Expand Down
13 changes: 9 additions & 4 deletions internal/utils/file.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package utils

type File struct {
type FileUpload struct {
Size int64
Current int64
Name string
}

func (m File) UpdateCurrent(current int64) File {
func (m FileUpload) UpdateCurrent(current int64) FileUpload {
m.Current = current
return m
}

func NewFile(size int64, current int64, name string) File {
return File{
func NewFile(size int64, current int64, name string) FileUpload {
return FileUpload{
Name: name,
Current: current,
Size: size,
}
}

type File struct {
Size string
Name string
}
Loading