-
Notifications
You must be signed in to change notification settings - Fork 0
/
ax
executable file
·58 lines (47 loc) · 1.53 KB
/
ax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env ruby
# frozen_string_literal: true
# grab gems for all sub-scripts, without needing separate Gemfile
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'damerau-levenshtein', require: 'damerau-levenshtein'
gem 'down', require: 'down'
gem 'open3', require: 'open3'
gem 'rubocop', require: false
end
require_relative 'check_devices'
require_relative 'find_unknown_value'
require_relative 'print_manual'
require_relative 'Commands'
input_command = ARGV[0]
if input_command.nil?
print_manual
return
end
matching_command = Commands::KNOWN_COMMANDS.find do |command|
command.name == ARGV[0]
end
if matching_command.nil?
# performs partial and Levenshtein
possible_commands = find_unknown_value(Commands::KNOWN_COMMAND_NAMES, input_command)
# also search for "semantically similar"
Commands::KNOWN_COMMANDS.each do |command|
possible_commands << command.name if command.similar_sounding_commands&.include? input_command
end
# remove duplicates and sort from possible_commands
possible_commands = possible_commands
.uniq
.sort { |a, b| a <=> b }
unless possible_commands.empty?
puts 'Did you mean?'
possible_commands.each do |command|
puts " #{command}" # TODO: consider printing entire manual line for this command
end
end
return
end
# perform device check
return unless check_devices
# strip command from ARGV and pass remaining
other_args = ARGV.drop(1)
matching_command.perform(*other_args) # convert array into arg list