Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
chromebrew
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
chromebrew
Commits
af9a750d
Commit
af9a750d
authored
Nov 02, 2017
by
Yan Couto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Command suggestions
When you mistype a command, it shows similar commands.
parent
f030aa5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
crew
crew
+11
-0
lib/util.rb
lib/util.rb
+31
-0
No files found.
crew
View file @
af9a750d
...
...
@@ -11,6 +11,7 @@ require 'digest/sha2'
require
'json'
require
'fileutils'
require_relative
'lib/const'
require_relative
'lib/util'
#
Add
lib
to
LOAD_PATH
$
LOAD_PATH
.
unshift
"#{CREW_LIB_PATH}lib"
...
...
@@ -51,6 +52,16 @@ require_relative 'lib/docopt'
begin
args
=
Docopt
::
docopt
(
DOC
)
rescue
Docopt
::
Exit
=>
e
puts
"Could not understand
\"
crew #{ARGV.join(' ')}
\"
."
.
lightred
cmds
=
[
"build"
,
"download"
,
"files"
,
"help"
,
"install"
,
"remove"
,
"search"
,
"update"
,
"upgrade"
,
"whatprovides"
]
#
Looking
for
similar
commands
if
ARGV
.
size
>=
1
and
not
cmds
.
include
?(
ARGV
[
0
])
then
similar
=
cmds
.
select
{|
word
|
edit_distance
(
ARGV
[
0
],
word
)
<
4
}
if
not
similar
.
empty
?
then
puts
"Did you mean?"
similar
.
each
{|
sug
|
puts
" #{sug}"
}
end
end
puts
e
.
message
exit
1
end
...
...
lib/util.rb
0 → 100644
View file @
af9a750d
require
"matrix"
class
MutableMatrix
<
Matrix
public
:"[]="
end
# Returns the edit distance between strings a and b
# https://en.wikipedia.org/wiki/Edit_distance
def
edit_distance
(
a
,
b
)
# memo is the matrix for dynamic programming
# memo[i, j] = the edit distance between the
# prefixes of a and b of size i and j.
memo
=
MutableMatrix
.
zero
(
a
.
size
+
1
,
b
.
size
+
1
)
a
.
size
.
times
{
|
i
|
memo
[
i
+
1
,
0
]
=
i
+
1
}
b
.
size
.
times
{
|
j
|
memo
[
0
,
j
+
1
]
=
j
+
1
}
a
.
size
.
times
do
|
i
|
b
.
size
.
times
do
|
j
|
if
a
[
i
]
==
b
[
j
]
then
memo
[
i
+
1
,
j
+
1
]
=
memo
[
i
,
j
]
else
memo
[
i
+
1
,
j
+
1
]
=
[
memo
[
i
+
1
,
j
],
memo
[
i
,
j
+
1
],
memo
[
i
,
j
]
].
min
+
1
end
end
end
return
memo
[
a
.
size
,
b
.
size
]
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment