Skip to content

Commit 6532de4

Browse files
committed
Smart matching for known images.
Signed-off-by: Anurag Priyam <[email protected]>
1 parent 146a28a commit 6532de4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

bin/oswitch

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ if options[:list]
4747
exit
4848
end
4949

50-
package = ARGV[0]
51-
command = ARGV[1..-1]
52-
OSwitch.to(package, command)
50+
pattern = ARGV[0].strip
51+
command = ARGV[1..-1].join(' ')
52+
matches = OSwitch.packages.grep(/#{pattern}/)
53+
54+
if matches.length > 1
55+
puts "Which one of the following did you mean?"
56+
puts matches.join(', ')
57+
else
58+
OSwitch.to(matches.first || pattern, command)
59+
end

lib/oswitch.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def packages
4040
end
4141

4242
def initialize(package, command = [])
43-
@package = package.strip
44-
@command = command.join(' ')
43+
@package = package
44+
@command = command
4545
@imgname = "oswitch_#{@package}"
4646
@cntname = "#{@package.gsub(%r{/|:}, '_')}-#{Process.pid}"
4747
exec

0 commit comments

Comments
 (0)