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
16 changes: 16 additions & 0 deletions eos/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,22 @@ func TestAttrSetArgs(t *testing.T) {
}
}

func TestMkdirRunsEOSMkdir(t *testing.T) {
runner := &recordingRunner{}
c := &Client{timeout: time.Second, runner: runner}

if err := c.Mkdir(context.Background(), "/eos/test/new-dir"); err != nil {
t.Fatalf("Mkdir() error: %v", err)
}
if len(runner.calls) != 1 {
t.Fatalf("expected one command, got %d", len(runner.calls))
}
call := runner.calls[0]
if call.name != "eos" || strings.Join(call.args, " ") != "mkdir /eos/test/new-dir" {
t.Fatalf("expected eos mkdir command, got %+v", call)
}
}

func TestRTLogCommand(t *testing.T) {
got := shellDisplayJoin([]string{"eos", "rtlog", "/eos/fst01.cern.ch:1095/fst", "600", "info"})
want := "eos rtlog /eos/fst01.cern.ch:1095/fst 600 info"
Expand Down
8 changes: 8 additions & 0 deletions eos/fetch_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func (c *Client) SetAttr(ctx context.Context, rawPath, key, value string, recurs
return nil
}

func (c *Client) Mkdir(ctx context.Context, rawPath string) error {
_, err := c.runCommandContext(ctx, "eos", "mkdir", rawPath)
if err != nil {
return fmt.Errorf("eos mkdir: %w", err)
}
return nil
}

func attrSetArgs(rawPath, key, value string, recursive bool) []string {
args := []string{"eos", "attr"}
if recursive {
Expand Down
7 changes: 7 additions & 0 deletions ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ func runNamespaceAttrSetCmd(client *eos.Client, path, key, value string, recursi
}
}

func runNamespaceMkdirCmd(client *eos.Client, path string) tea.Cmd {
return func() tea.Msg {
err := client.Mkdir(context.Background(), path)
return namespaceMkdirResultMsg{path: path, err: err}
}
}

func loadSpaceStatusCmd(client *eos.Client, space string) tea.Cmd {
return func() tea.Msg {
records, err := client.SpaceStatus(context.Background(), space)
Expand Down
42 changes: 41 additions & 1 deletion ui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ func (m model) updateNamespaceKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.status = fmt.Sprintf("Opening %s...", parent)
return m, loadDirectoryCmd(m.client, parent)
}
case "enter":
case "enter", "a":
return m.startNamespaceAttrEdit()
case "m":
return m.startNamespaceMkdir()
case ":":
return m.startNamespaceGoTo()
case "right":
Expand Down Expand Up @@ -446,6 +448,40 @@ func (m model) updateNamespaceGoToKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
return m, cmd
}

func (m model) startNamespaceMkdir() (tea.Model, tea.Cmd) {
input := textinput.New()
input.Prompt = "name> "
input.CharLimit = 4096
input.Width = 48

m.nsMkdir = namespaceMkdir{
active: true,
input: input,
}
return m, m.nsMkdir.input.Focus()
}

func (m model) updateNamespaceMkdirKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "esc":
m.nsMkdir.active = false
return m, nil
case "enter":
target := resolveNamespacePath(m.directory.Path, m.nsMkdir.input.Value())
if target == "" || target == m.directory.Path {
m.status = "Enter a new directory name"
return m, nil
}
m.nsMkdir.active = false
m.status = fmt.Sprintf("Creating directory %s...", target)
return m, runNamespaceMkdirCmd(m.client, target)
}

var cmd tea.Cmd
m.nsMkdir.input, cmd = m.nsMkdir.input.Update(msg)
return m, cmd
}

func (m model) updateSpacesKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
spaces := m.visibleSpaces()
half := max(1, m.height/6)
Expand Down Expand Up @@ -1007,7 +1043,11 @@ func (m model) updatePopup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.closeFilterPopup("Filter selection cancelled")
return m, nil
case "enter":
view := m.popup.view
m.applyPopupSelection()
if view == viewNamespace {
return m.startNamespaceAttrLoad(false)
}
return m, nil
case "up", "down", "pgup", "pgdown", "home", "end":
var cmd tea.Cmd
Expand Down
19 changes: 19 additions & 0 deletions ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.nsGoTo.active {
return m.updateNamespaceGoToKeys(msg)
}
if m.nsMkdir.active {
return m.updateNamespaceMkdirKeys(msg)
}
if m.ioShapingEdit.active {
return m.updateIOShapingPolicyEditKeys(msg)
}
Expand Down Expand Up @@ -544,6 +547,20 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.status = fmt.Sprintf("Updated attributes on %s", msg.path)
}
return m.startNamespaceAttrLoad(true)
case namespaceMkdirResultMsg:
m.nsMkdir.active = false
if msg.err != nil {
m.alert = errorAlert{
active: true,
message: fmt.Sprintf("mkdir failed: %v", msg.err),
}
return m, nil
}
m.nsFilter.filters = map[int]string{}
m.nsSelected = 0
m.nsLoading = true
m.status = fmt.Sprintf("Created directory %s", msg.path)
return m, loadDirectoryCmd(m.client, m.directory.Path)
case spaceStatusLoadedMsg:
if msg.space != m.spaceStatusTarget {
return m, nil
Expand Down Expand Up @@ -796,6 +813,8 @@ func (m model) View() string {
body = m.renderOverlay(body, m.renderNamespaceAttrEditPopup(), bodyTotalHeight)
} else if m.nsGoTo.active {
body = m.renderOverlay(body, m.renderNamespaceGoToPopup(), bodyTotalHeight)
} else if m.nsMkdir.active {
body = m.renderOverlay(body, m.renderNamespaceMkdirPopup(), bodyTotalHeight)
} else if m.ioShapingEdit.active {
body = m.renderOverlay(body, m.renderIOShapingPolicyEditPopup(), bodyTotalHeight)
} else if m.groupDrain.active {
Expand Down
Loading
Loading