Skip to content

Commit 8f9913d

Browse files
committed
revert and remove CommandScopes
1 parent eaa04f7 commit 8f9913d

File tree

6 files changed

+153
-122
lines changed

6 files changed

+153
-122
lines changed

edge/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM dannyben/alpine-ruby
2+
3+
ENV PS1 "\n\n>> bashly \W \$ "
4+
RUN apk add --no-cache git
5+
6+
WORKDIR /bashly
7+
RUN git clone --depth 1 https://github.com/DannyBen/bashly.git .
8+
RUN gem build bashly.gemspec
9+
RUN gem install bashly*.gem
10+
11+
WORKDIR /app
12+
VOLUME /app
13+
ENTRYPOINT ["bashly"]

edge/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Testing Unreleased (Edge) Bashly Versions
2+
3+
If you wish to try a version of bashly straight from GitHub before it is
4+
released, you can use one of these methods:
5+
6+
## Using Docker
7+
8+
```bash
9+
alias bashly_edge='docker run --rm -it --user $(id -u):$(id -g) --volume "$PWD:/app" dannyben/bashly:edge'
10+
```
11+
12+
or build your own image with [this Dockerfile](Dockerfile).
13+
14+
## Using Ruby
15+
16+
```bash
17+
git clone --depth 1 https://github.com/DannyBen/bashly.git
18+
cd bashly
19+
gem build bashly.gemspec
20+
gem install bashly*.gem
21+
cd ..
22+
```

edge/op.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build: docker build -t dannyben/bashly:edge . && docker images |grep bashly
2+
push: docker push dannyben/bashly:edge

lib/bashly/concerns/command_scopes.rb

Lines changed: 0 additions & 104 deletions
This file was deleted.

lib/bashly/concerns/renderable.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ def view_marker(id = nil)
1818
"# #{id}" unless Settings.production?
1919
end
2020

21+
# Reads a file from the userspace (Settings.source_dir) and returns
22+
# its contents. If the file is not found, returns a string with a hint.
23+
def load_user_file(file, placeholder: true)
24+
path = "#{Settings.source_dir}/#{file}"
25+
26+
content = if File.exist? path
27+
File.read(path).remove_front_matter
28+
elsif placeholder
29+
%q[echo "error: cannot load file"]
30+
else
31+
''
32+
end
33+
34+
Settings.production? ? content : "#{view_marker path}\n#{content}"
35+
end
36+
2137
private
2238

2339
def view_path(view)

lib/bashly/script/command.rb

Lines changed: 100 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module Bashly
22
module Script
33
class Command < Base
44
include Completions::Command
5-
include CommandScopes
65

76
class << self
87
def option_keys
@@ -32,6 +31,16 @@ def aliases
3231
[name] + alt
3332
end
3433

34+
# Returns an array of all full names (including aliases and aliases of
35+
# parents)
36+
def all_full_names
37+
if parent_command
38+
parent_command.all_full_names.product(aliases).map { |a| a.join ' ' }
39+
else
40+
aliases
41+
end
42+
end
43+
3544
# Returns an array of alternative aliases if any
3645
def alt
3746
# DEPRECATION 0.8.0
@@ -57,6 +66,33 @@ def catch_all
5766
@catch_all ||= CatchAll.from_config options['catch_all']
5867
end
5968

69+
# Returns a full list of the Command names and aliases combined
70+
def command_aliases
71+
commands.map(&:aliases).flatten
72+
end
73+
74+
# Returns a data structure for displaying subcommands help
75+
def command_help_data
76+
result = {}
77+
78+
public_commands.each do |command|
79+
result[command.group_string] ||= {}
80+
result[command.group_string][command.name] = command.summary_string
81+
next unless command.expose
82+
83+
command.public_commands.each do |subcommand|
84+
result[command.group_string]["#{command.name} #{subcommand.name}"] = subcommand.summary_string
85+
end
86+
end
87+
88+
result
89+
end
90+
91+
# Returns only the names of the Commands
92+
def command_names
93+
commands.map &:name
94+
end
95+
6096
# Returns an array of the Commands
6197
def commands
6298
return [] unless options["commands"]
@@ -67,6 +103,40 @@ def commands
67103
end
68104
end
69105

106+
# Returns a flat array containing all the commands in this tree.
107+
# This includes self + children + grandchildres + ...
108+
def deep_commands
109+
result = []
110+
commands.each do |command|
111+
result << command
112+
if command.commands.any?
113+
result += command.deep_commands
114+
end
115+
end
116+
result
117+
end
118+
119+
# If any of this command's subcommands has the default option set to
120+
# true, this default command will be returned, nil otherwise.
121+
def default_command
122+
commands.find { |c| c.default }
123+
end
124+
125+
# Returns an array of all the default Args
126+
def default_args
127+
args.select &:default
128+
end
129+
130+
# Returns an array of all the default Environment Variables
131+
def default_environment_variables
132+
environment_variables.select &:default
133+
end
134+
135+
# Returns an array of all the default Flags
136+
def default_flags
137+
flags.select &:default
138+
end
139+
70140
# Returns an array of EnvironmentVariables
71141
def environment_variables
72142
return [] unless options["environment_variables"]
@@ -109,23 +179,6 @@ def group_string
109179
end
110180
end
111181

112-
# Reads a file from the userspace (Settings.source_dir) and returns
113-
# its contents.
114-
# If the file is not found, returns a string with a hint.
115-
def load_user_file(file, placeholder: true)
116-
path = "#{Settings.source_dir}/#{file}"
117-
118-
content = if File.exist? path
119-
File.read(path).remove_front_matter
120-
elsif placeholder
121-
%q[echo "error: cannot load file"]
122-
else
123-
''
124-
end
125-
126-
Settings.production? ? content : "#{view_marker path}\n#{content}"
127-
end
128-
129182
# Returns the Command instance of the direct parent
130183
def parent_command
131184
options['parent_command']
@@ -137,11 +190,31 @@ def parents
137190
options['parents'] || []
138191
end
139192

193+
# Returns only commands that are not private
194+
def public_commands
195+
commands.reject &:private
196+
end
197+
140198
# Returns true if one of the args is repeatable
141199
def repeatable_arg_exist?
142200
args.select(&:repeatable).any?
143201
end
144202

203+
# Returns an array of all the required Arguments
204+
def required_args
205+
args.select &:required
206+
end
207+
208+
# Returns an array of all the required EnvironmentVariables
209+
def required_environment_variables
210+
environment_variables.select &:required
211+
end
212+
213+
# Returns an array of all the required Flags
214+
def required_flags
215+
flags.select &:required
216+
end
217+
145218
# Returns true if this is the root command (no parents)
146219
def root_command?
147220
parents.empty?
@@ -180,6 +253,15 @@ def user_lib
180253
@user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.sh"].sort
181254
end
182255

256+
# Returns an array of all the args with a whitelist
257+
def whitelisted_args
258+
args.select &:allowed
259+
end
260+
261+
# Returns an array of all the flags with a whitelist arg
262+
def whitelisted_flags
263+
flags.select &:allowed
264+
end
183265
end
184266
end
185267
end

0 commit comments

Comments
 (0)