Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
805be62f
Commit
805be62f
authored
May 15, 2015
by
Olivier Halligon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving `choose_from_array` to UserInterface
parent
547e7e89
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
35 deletions
+43
-35
spec.rb
lib/cocoapods/command/spec.rb
+0
-17
cat.rb
lib/cocoapods/command/spec/cat.rb
+1
-1
edit.rb
lib/cocoapods/command/spec/edit.rb
+1
-1
user_interface.rb
lib/cocoapods/user_interface.rb
+25
-0
spec_spec.rb
spec/functional/command/spec_spec.rb
+0
-16
user_interface_spec.rb
spec/unit/user_interface_spec.rb
+16
-0
No files found.
lib/cocoapods/command/spec.rb
View file @
805be62f
...
...
@@ -30,23 +30,6 @@ module Pod
help!
'A valid regular expression is required.'
end
# @return [Fixnum] the index of the chosen array item
#
def
choose_from_array
(
array
,
message
)
array
.
each_with_index
do
|
item
,
index
|
UI
.
puts
"
#{
index
+
1
}
:
#{
item
}
"
end
UI
.
puts
message
index
=
UI
.
gets
.
chomp
.
to_i
-
1
if
index
<
0
||
index
>
array
.
count
-
1
raise
Informative
,
"
#{
index
+
1
}
is invalid [1-
#{
array
.
count
}
]"
else
index
end
end
# @param [String] spec
# The name of the specification.
#
...
...
lib/cocoapods/command/spec/cat.rb
View file @
805be62f
...
...
@@ -37,7 +37,7 @@ module Pod
query
=
@use_regex
?
@query
:
Regexp
.
escape
(
@query
)
filepath
=
if
@show_all
specs
=
get_path_of_spec
(
query
,
@show_all
).
split
(
/\n/
)
index
=
choose_from_array
(
specs
,
"Which spec would you like to print [1-
#{
specs
.
count
}
]? "
)
index
=
UI
.
choose_from_array
(
specs
,
"Which spec would you like to print [1-
#{
specs
.
count
}
]? "
)
specs
[
index
]
else
get_path_of_spec
(
query
)
...
...
lib/cocoapods/command/spec/edit.rb
View file @
805be62f
...
...
@@ -38,7 +38,7 @@ module Pod
if
@show_all
specs
=
get_path_of_spec
(
query
,
@show_all
).
split
(
/\n/
)
message
=
"Which spec would you like to edit [1-
#{
specs
.
count
}
]? "
index
=
choose_from_array
(
specs
,
message
)
index
=
UI
.
choose_from_array
(
specs
,
message
)
filepath
=
specs
[
index
]
else
filepath
=
get_path_of_spec
(
query
)
...
...
lib/cocoapods/user_interface.rb
View file @
805be62f
...
...
@@ -285,6 +285,31 @@ module Pod
end
end
# Asks the use to choose an option from a list
#
# @param [Array<String>] array
# The list of options to choose from
#
# @param [String] message
# The prompt to show as the question to choose from the list
#
# @return [Fixnum] the index of the chosen array item
#
def
choose_from_array
(
array
,
message
)
array
.
each_with_index
do
|
item
,
index
|
UI
.
puts
"
#{
index
+
1
}
:
#{
item
}
"
end
UI
.
puts
message
index
=
UI
.
gets
.
chomp
.
to_i
-
1
if
index
<
0
||
index
>
array
.
count
-
1
raise
Informative
,
"
#{
index
+
1
}
is invalid [1-
#{
array
.
count
}
]"
else
index
end
end
public
# @!group Basic methods
...
...
spec/functional/command/spec_spec.rb
View file @
805be62f
...
...
@@ -364,22 +364,6 @@ module Pod
path
.
should
==
fixture
(
'spec-repos'
)
+
'master/Specs/AFNetworking/2.4.1/AFNetworking.podspec.json'
end
end
describe
'#choose_from_array'
do
it
'should return a valid index for the given array'
do
UI
.
next_input
=
"1
\n
"
index
=
@command
.
send
(
:choose_from_array
,
%w(item1 item2 item3)
,
'A message'
)
UI
.
output
.
should
.
include
"1: item1
\n
2: item2
\n
3: item3
\n
A message
\n
"
index
.
should
==
0
end
it
'should raise when the index is out of bounds'
do
UI
.
next_input
=
"4
\n
"
lambda
{
@command
.
send
(
:choose_from_array
,
%w(item1 item2 item3)
,
'A message'
)
}.
should
.
raise
Pod
::
Informative
UI
.
next_input
=
"0
\n
"
lambda
{
@command
.
send
(
:choose_from_array
,
%w(item1 item2 item3)
,
'A message'
)
}.
should
.
raise
Pod
::
Informative
end
end
end
#-------------------------------------------------------------------------#
...
...
spec/unit/user_interface_spec.rb
View file @
805be62f
...
...
@@ -71,5 +71,21 @@ module Pod
UI
.
output
.
should
==
"
#{
' '
*
10
}
- label:
\n
"
+
values
.
map
{
|
v
|
"
#{
' '
*
12
}
-
#{
v
}
\n
"
}.
join
end
end
describe
'#choose_from_array'
do
it
'should return a valid index for the given array'
do
UI
.
next_input
=
"1
\n
"
index
=
UI
.
choose_from_array
(
%w(item1 item2 item3)
,
'A message'
)
UI
.
output
.
should
.
include
"1: item1
\n
2: item2
\n
3: item3
\n
A message
\n
"
index
.
should
==
0
end
it
'should raise when the index is out of bounds'
do
UI
.
next_input
=
"4
\n
"
lambda
{
UI
.
choose_from_array
(
%w(item1 item2 item3)
,
'A message'
)
}.
should
.
raise
Pod
::
Informative
UI
.
next_input
=
"0
\n
"
lambda
{
UI
.
choose_from_array
(
%w(item1 item2 item3)
,
'A message'
)
}.
should
.
raise
Pod
::
Informative
end
end
end
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