-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Support pipelines. #299
base: master
Are you sure you want to change the base?
Support pipelines. #299
Conversation
The first commit on this branch works on macOS, but not on Linux (e.g. on CI). The difference seems to be how sh(1) handles SIGINT when run with To experiment, I wrote a little Ruby script that does nothing until it gets a SIGINT: # test.rb
begin
sleep
rescue Interrupt
puts 'SIGINT!'
end When I spawn a new process that runs this script directly, I can easily send it an interrupt:
However, when I spawn a new process that runs the script in a shell, I can't interrupt it:
Note that in this case The only vaguely useful reference to this I've found so far is a line in some Docker documentation:
|
6ba89fb
to
5e5b312
Compare
it 'parses two commands combined with |' do | ||
result = parse(tokens( | ||
[:WORD, 'log'], [:PIPE], [:WORD, '!wc'], [:EOS], | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TrailingCommaInArguments: Put a comma after the last parameter of a multiline method call.
@@ -169,6 +169,14 @@ | |||
expect(result).to be_a(Gitsh::Commands::Tree::Multi) | |||
end | |||
|
|||
it 'parses two commands combined with |' do | |||
result = parse(tokens( | |||
[:WORD, 'log'], [:PIPE], [:WORD, '!wc'], [:EOS], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/FirstParameterIndentation: Indent the first parameter one step more than tokens(.
def build_env | ||
Gitsh::Environment.new( | ||
input_stream: instance_double(IO, read: ""), | ||
output_stream: StringIO.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TrailingCommaInArguments: Put a comma after the last parameter of a multiline method call.
|
||
def build_env | ||
Gitsh::Environment.new( | ||
input_stream: instance_double(IO, read: ""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
end | ||
end | ||
|
||
def create_command_double(value=true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
context 'when the left command fails' do | ||
it 'returns false' do | ||
left_command = create_command_double(false) { '' } | ||
right_command = create_command_double { |input| input.upcase } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolProc: Pass &:upcase as an argument to create_command_double instead of a block.
describe '#execute' do | ||
it 'pipes output of left command to right command' do | ||
left_command = create_command_double { 'string' } | ||
right_command = create_command_double { |input| input.upcase } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolProc: Pass &:upcase as an argument to create_command_double instead of a block.
@@ -36,6 +37,7 @@ class Parser < RLTK::Parser | |||
clause('.commands SEMICOLON .commands') { |c1, c2| Commands::Tree::Multi.new(c1, c2) } | |||
clause('.commands OR .commands') { |c1, c2| Commands::Tree::Or.new(c1, c2) } | |||
clause('.commands AND .commands') { |c1, c2| Commands::Tree::And.new(c1, c2) } | |||
clause('.commands PIPE .commands') { |c1, c2| Commands::Pipeline.new(c1, c2) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [84/80]
it 'parses two commands combined with |' do | ||
result = parse(tokens( | ||
[:WORD, 'log'], [:PIPE], [:WORD, '!wc'], [:EOS], | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TrailingCommaInArguments: Put a comma after the last parameter of a multiline method call.
@@ -169,6 +169,14 @@ | |||
expect(result).to be_a(Gitsh::Commands::Tree::Multi) | |||
end | |||
|
|||
it 'parses two commands combined with |' do | |||
result = parse(tokens( | |||
[:WORD, 'log'], [:PIPE], [:WORD, '!wc'], [:EOS], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/FirstParameterIndentation: Indent the first parameter one step more than tokens(.
def build_env | ||
Gitsh::Environment.new( | ||
input_stream: instance_double(IO, read: ""), | ||
output_stream: StringIO.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TrailingCommaInArguments: Put a comma after the last parameter of a multiline method call.
|
||
def build_env | ||
Gitsh::Environment.new( | ||
input_stream: instance_double(IO, read: ""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
end | ||
end | ||
|
||
def create_command_double(value=true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
context 'when the left command fails' do | ||
it 'returns false' do | ||
left_command = create_command_double(false) { '' } | ||
right_command = create_command_double { |input| input.upcase } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolProc: Pass &:upcase as an argument to create_command_double instead of a block.
describe '#execute' do | ||
it 'pipes output of left command to right command' do | ||
left_command = create_command_double { 'string' } | ||
right_command = create_command_double { |input| input.upcase } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolProc: Pass &:upcase as an argument to create_command_double instead of a block.
@@ -36,6 +37,7 @@ class Parser < RLTK::Parser | |||
clause('.commands SEMICOLON .commands') { |c1, c2| Commands::Tree::Multi.new(c1, c2) } | |||
clause('.commands OR .commands') { |c1, c2| Commands::Tree::Or.new(c1, c2) } | |||
clause('.commands AND .commands') { |c1, c2| Commands::Tree::And.new(c1, c2) } | |||
clause('.commands PIPE .commands') { |c1, c2| Commands::Pipeline.new(c1, c2) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [84/80]
Here’s another possibly relevant snippet of documentation from OpenBSD’s
Would it make sense for |
Ok, I had a play around with this and I think I got it to work: https://gist.github.com/sharplet/5dc8bd4239e09f68e8f009dbfe48f9ff#file-subshell-swift-L23. This sets up a signal handler for SIGINT that calls Using |
Two commands combined with the pipe character (`|`) will be run in parallel with the standard output of the first command connected to the standard input of the second command via an `IO.pipe`.
Two commands combined with the pipe character (
|
) will be run in parallel with the standard output of the first command connected to the standard input of the second command via anIO.pipe
.