This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
--only
/--ignore
parameters on Theme pull
/push
command…
…s to work without quotes (#2066)
- Loading branch information
Showing
17 changed files
with
531 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
module Theme | ||
class Command | ||
module Common | ||
module RootHelper | ||
def root_value(options, name) | ||
argv = default_argv(options) | ||
command_index = argv.index(name.to_s) | ||
|
||
return "." if command_index.nil? | ||
|
||
next_index = command_index + 1 | ||
option_by_key = options_map(options) | ||
|
||
while next_index < argv.size | ||
element = argv[next_index] | ||
option = option_by_key[element] | ||
|
||
return element if option.nil? | ||
|
||
# Skip the option argument | ||
next_index += 1 unless option.arg.nil? | ||
|
||
# PATTERN arguments take precedence over the `root` | ||
if option.arg =~ /PATTERN/ | ||
next_index += 1 while option_argument?(argv, next_index, option_by_key) | ||
next | ||
end | ||
|
||
next_index += 1 | ||
end | ||
|
||
"." | ||
end | ||
|
||
private | ||
|
||
def default_argv(options) | ||
options.parser.default_argv | ||
end | ||
|
||
def options_map(options) | ||
map = {} | ||
options_list(options).each do |option| | ||
map[option.short.first] = option | ||
map[option.long.first] = option | ||
end | ||
map | ||
end | ||
|
||
def options_list(options) | ||
options.parser.top.list | ||
end | ||
|
||
def option_argument?(argv, next_index, option_by_key) | ||
return false unless next_index < argv.size | ||
|
||
element = argv[next_index] | ||
option_by_key[element].nil? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Theme | ||
module Conversions | ||
class BaseGlob | ||
class << self | ||
def register(parser) | ||
parser.accept(self) { |_val| convert(parser) } | ||
end | ||
|
||
def convert(parser) | ||
argv = parser.default_argv | ||
option_index = argv.index { |v| options.include?(v) } | ||
|
||
return [] if option_index.nil? | ||
|
||
start_index = option_index + 1 | ||
option_by_key = options_map(parser) | ||
values = [] | ||
|
||
argv[start_index..-1].each do |value| | ||
return values unless option_by_key[value].nil? | ||
values << value | ||
end | ||
|
||
values | ||
end | ||
|
||
def options | ||
raise "`#{self.class.name}#options` must be defined" | ||
end | ||
|
||
private | ||
|
||
def options_map(parser) | ||
map = {} | ||
parser.top.list.each do |option| | ||
map[option.short.first] = option | ||
map[option.long.first] = option | ||
end | ||
map | ||
end | ||
|
||
def parameter?(value) | ||
value.start_with?("-") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "base_glob" | ||
|
||
module Theme | ||
module Conversions | ||
class IgnoreGlob < BaseGlob | ||
class << self | ||
def options | ||
%w(-x --ignore) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "base_glob" | ||
|
||
module Theme | ||
module Conversions | ||
class IncludeGlob < BaseGlob | ||
class << self | ||
def options | ||
%w(-o --only) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.