Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow combined multiple args (fixes #622) #623

Merged
merged 2 commits into from
Nov 27, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
/bin/*
.idea/
.ropeproject/

# E2E
__pycache__
15 changes: 11 additions & 4 deletions skim/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,20 @@ pub struct SkimOptions {
/// 2.. From the 2nd field to the last field
/// ..-3 From the 1st field to the 3rd to the last field
/// .. All the fields
#[arg(short, long, default_value = "", help_heading = "Search", verbatim_doc_comment)]
#[arg(
short,
long,
default_value = "",
help_heading = "Search",
verbatim_doc_comment,
value_delimiter = ','
)]
pub nth: Vec<String>,

/// Fields to be transformed
///
/// See **nth** for the details
#[arg(long, default_value = "", help_heading = "Search")]
#[arg(long, default_value = "", help_heading = "Search", value_delimiter = ',')]
pub with_nth: Vec<String>,

/// Delimiter between fields
Expand Down Expand Up @@ -302,7 +309,7 @@ pub struct SkimOptions {
///
/// If the query is empty, skim will execute abort action, otherwise execute delete-char action. It
/// is equal to ‘delete-char/eof‘.
#[arg(short, long, help_heading = "Interface", verbatim_doc_comment)]
#[arg(short, long, help_heading = "Interface", verbatim_doc_comment, value_delimiter = ',')]
pub bind: Vec<String>,

/// Enable multiple selection
Expand Down Expand Up @@ -576,7 +583,7 @@ pub struct SkimOptions {
/// list.
///
/// e.g. sk --expect=ctrl-v,ctrl-t,alt-s --expect=f1,f2,~,@
#[arg(long, help_heading = "Scripting")]
#[arg(long, help_heading = "Scripting", value_delimiter = ',')]
pub expect: Vec<String>,

/// Read input delimited by ASCII NUL(\\0) characters
Expand Down
14 changes: 14 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

TEST_CLASS=test_skim.TestSkim

tests=$(sed -n 's/^\s\+def \(test_\w\+\)(self.*):\s*$/\1/p' test_skim.py | \
sk --multi)

cargo build --release

for test in $tests; do
python3 -m unittest $TEST_CLASS.$test
done
33 changes: 33 additions & 0 deletions test/test_skim.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,39 @@ def test_tiebreak_neg_length(self):
self.tmux.send_keys('c')
self.tmux.until(lambda l: l[-3].startswith('> ac'))

def test_622_combined_multiple_flags_expect(self):
input_cmd = "echo -e 'a b c\\nd e f'"
args = '--expect ctrl-a,ctrl-b'
self.tmux.send_keys(f"{input_cmd} | {self.sk(args)}", Key('Enter'))
self.tmux.until(lambda l: l.ready_with_matches(2))
self.tmux.send_keys(Ctrl('a'))
out = self.readonce().split('\n')
self.assertEqual(out[-1], '')
self.assertEqual(out[-2], 'a b c')
self.assertEqual(out[-3], 'ctrl-a')
self.tmux.send_keys(f"{input_cmd} | {self.sk(args)}", Key('Enter'))
self.tmux.until(lambda l: l.ready_with_matches(2))
self.tmux.send_keys(Ctrl('b'))
out = self.readonce().split('\n')
self.assertEqual(out[-1], '')
self.assertEqual(out[-2], 'a b c')
self.assertEqual(out[-3], 'ctrl-b')

def test_622_combined_multiple_flags_nth(self):
input_cmd = "echo -e 'a b c\nd e f'"
args = '--nth 1,2'
self.tmux.send_keys(f"{input_cmd} | {self.sk(args)}", Key('Enter'))
self.tmux.until(lambda l: l.ready_with_matches(2))
self.tmux.send_keys('c')
self.tmux.until(lambda l: l.ready_with_matches(0))

def test_622_combined_multiple_flags_with_nth(self):
input_cmd = "echo -e 'a b c\nd e f'"
args = '--with-nth 1,2'
self.tmux.send_keys(f"{input_cmd} | {self.sk(args)}", Key('Enter'))
self.tmux.until(lambda l: l.ready_with_matches(2))
self.tmux.until(lambda l: l[-3] == '> a b')

def find_prompt(lines, interactive=False, reverse=False):
linen = -1
prompt = ">"
Expand Down
Loading