Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
1
Merge Requests
1
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
gitlab-ce
Commits
b722b62a
Commit
b722b62a
authored
Jan 31, 2022
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Readline.readline for feature_flag binary
parent
65b7fc1a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
30 deletions
+26
-30
bin/feature-flag
bin/feature-flag
+6
-10
spec/bin/feature_flag_spec.rb
spec/bin/feature_flag_spec.rb
+20
-20
No files found.
bin/feature-flag
View file @
b722b62a
...
...
@@ -9,6 +9,7 @@ require 'optparse'
require
'yaml'
require
'fileutils'
require
'uri'
require
'readline'
require_relative
'../lib/feature/shared'
unless
defined?
(
Feature
::
Shared
)
...
...
@@ -114,8 +115,7 @@ class FeatureFlagOptionParser
$stdout
.
puts
">> Specify the group introducing the feature flag, like `group::apm`:"
loop
do
$stdout
.
print
"?> "
group
=
$stdin
.
gets
.
strip
group
=
Readline
.
readline
(
'?> '
,
false
)
&
.
strip
group
=
nil
if
group
.
empty?
return
group
if
group
.
nil?
||
group
.
start_with?
(
'group::'
)
...
...
@@ -137,9 +137,7 @@ class FeatureFlagOptionParser
end
loop
do
$stdout
.
print
"?> "
type
=
$stdin
.
gets
.
strip
.
to_sym
type
=
Readline
.
readline
(
'?> '
,
false
)
&
.
strip
&
.
to_sym
return
type
if
TYPES
[
type
]
&&
!
TYPES
[
type
][
:deprecated
]
$stderr
.
puts
"Invalid type specified '
#{
type
}
'"
...
...
@@ -151,8 +149,7 @@ class FeatureFlagOptionParser
$stdout
.
puts
">> URL of the MR introducing the feature flag (enter to skip):"
loop
do
$stdout
.
print
"?> "
introduced_by_url
=
$stdin
.
gets
.
strip
introduced_by_url
=
Readline
.
readline
(
'?> '
,
false
)
&
.
strip
introduced_by_url
=
nil
if
introduced_by_url
.
empty?
return
introduced_by_url
if
introduced_by_url
.
nil?
||
introduced_by_url
.
start_with?
(
'https://'
)
...
...
@@ -184,8 +181,7 @@ class FeatureFlagOptionParser
$stdout
.
puts
">> URL of the rollout issue (enter to skip):"
loop
do
$stdout
.
print
"?> "
created_url
=
$stdin
.
gets
.
strip
created_url
=
Readline
.
readline
(
'?> '
,
false
)
&
.
strip
created_url
=
nil
if
created_url
.
empty?
return
created_url
if
created_url
.
nil?
||
created_url
.
start_with?
(
'https://'
)
...
...
@@ -218,7 +214,7 @@ class FeatureFlagCreator
assert_name!
assert_existing_feature_flag!
# Read type from
$
stdin unless is already set
# Read type from stdin unless is already set
options
.
type
||=
FeatureFlagOptionParser
.
read_type
options
.
ee
||=
FeatureFlagOptionParser
.
read_ee_only
(
options
)
options
.
group
||=
FeatureFlagOptionParser
.
read_group
...
...
spec/bin/feature_flag_spec.rb
View file @
b722b62a
...
...
@@ -25,7 +25,7 @@ RSpec.describe 'bin/feature-flag' do
allow
(
File
).
to
receive
(
:write
).
and_return
(
true
)
# ignore stdin
allow
(
$stdin
).
to
receive
(
:gets
).
and_raise
(
'EOF'
)
allow
(
Readline
).
to
receive
(
:readline
).
and_raise
(
'EOF'
)
end
subject
{
creator
.
execute
}
...
...
@@ -135,8 +135,8 @@ RSpec.describe 'bin/feature-flag' do
let
(
:type
)
{
'deprecated'
}
it
'shows error message and retries'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
type
)
expect
(
$stdin
).
to
receive
(
:gets
).
and_raise
(
'EOF'
)
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
type
)
expect
(
Readline
).
to
receive
(
:readline
).
and_raise
(
'EOF'
)
expect
do
expect
{
described_class
.
read_type
}.
to
raise_error
(
/EOF/
)
...
...
@@ -154,8 +154,8 @@ RSpec.describe 'bin/feature-flag' do
)
end
it
'reads type from
$
stdin'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
type
)
it
'reads type from stdin'
do
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
type
)
expect
do
expect
(
described_class
.
read_type
).
to
eq
(
:development
)
end
.
to
output
(
/Specify the feature flag type/
).
to_stdout
...
...
@@ -165,8 +165,8 @@ RSpec.describe 'bin/feature-flag' do
let
(
:type
)
{
'invalid'
}
it
'shows error message and retries'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
type
)
expect
(
$stdin
).
to
receive
(
:gets
).
and_raise
(
'EOF'
)
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
type
)
expect
(
Readline
).
to
receive
(
:readline
).
and_raise
(
'EOF'
)
expect
do
expect
{
described_class
.
read_type
}.
to
raise_error
(
/EOF/
)
...
...
@@ -180,8 +180,8 @@ RSpec.describe 'bin/feature-flag' do
describe
'.read_group'
do
let
(
:group
)
{
'group::memory'
}
it
'reads type from
$
stdin'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
group
)
it
'reads type from stdin'
do
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
group
)
expect
do
expect
(
described_class
.
read_group
).
to
eq
(
'group::memory'
)
end
.
to
output
(
/Specify the group introducing the feature flag/
).
to_stdout
...
...
@@ -191,8 +191,8 @@ RSpec.describe 'bin/feature-flag' do
let
(
:type
)
{
'invalid'
}
it
'shows error message and retries'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
type
)
expect
(
$stdin
).
to
receive
(
:gets
).
and_raise
(
'EOF'
)
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
type
)
expect
(
Readline
).
to
receive
(
:readline
).
and_raise
(
'EOF'
)
expect
do
expect
{
described_class
.
read_group
}.
to
raise_error
(
/EOF/
)
...
...
@@ -205,8 +205,8 @@ RSpec.describe 'bin/feature-flag' do
describe
'.read_introduced_by_url'
do
let
(
:url
)
{
'https://merge-request'
}
it
'reads type from
$
stdin'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
url
)
it
'reads type from stdin'
do
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
url
)
expect
do
expect
(
described_class
.
read_introduced_by_url
).
to
eq
(
'https://merge-request'
)
end
.
to
output
(
/URL of the MR introducing the feature flag/
).
to_stdout
...
...
@@ -216,7 +216,7 @@ RSpec.describe 'bin/feature-flag' do
let
(
:url
)
{
''
}
it
'skips entry'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
url
)
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
url
)
expect
do
expect
(
described_class
.
read_introduced_by_url
).
to
be_nil
end
.
to
output
(
/URL of the MR introducing the feature flag/
).
to_stdout
...
...
@@ -227,8 +227,8 @@ RSpec.describe 'bin/feature-flag' do
let
(
:url
)
{
'invalid'
}
it
'shows error message and retries'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
url
)
expect
(
$stdin
).
to
receive
(
:gets
).
and_raise
(
'EOF'
)
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
url
)
expect
(
Readline
).
to
receive
(
:readline
).
and_raise
(
'EOF'
)
expect
do
expect
{
described_class
.
read_introduced_by_url
}.
to
raise_error
(
/EOF/
)
...
...
@@ -242,8 +242,8 @@ RSpec.describe 'bin/feature-flag' do
let
(
:options
)
{
double
(
'options'
,
name:
'foo'
,
type: :development
)
}
let
(
:url
)
{
'https://issue'
}
it
'reads type from
$
stdin'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
url
)
it
'reads type from stdin'
do
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
url
)
expect
do
expect
(
described_class
.
read_rollout_issue_url
(
options
)).
to
eq
(
'https://issue'
)
end
.
to
output
(
/URL of the rollout issue/
).
to_stdout
...
...
@@ -253,8 +253,8 @@ RSpec.describe 'bin/feature-flag' do
let
(
:type
)
{
'invalid'
}
it
'shows error message and retries'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
type
)
expect
(
$stdin
).
to
receive
(
:gets
).
and_raise
(
'EOF'
)
expect
(
Readline
).
to
receive
(
:readline
).
and_return
(
type
)
expect
(
Readline
).
to
receive
(
:readline
).
and_raise
(
'EOF'
)
expect
do
expect
{
described_class
.
read_rollout_issue_url
(
options
)
}.
to
raise_error
(
/EOF/
)
...
...
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