completely 0.8.0.rc3 → 0.8.0.rc5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c08af2e45d441174aa7ba877f55ce3ab49ed37c066abba5b522f404226c4fb09
4
- data.tar.gz: 4096cfb3dd365eece6ad5801cde77ca2127fe0500404839949d8e4b6a3c0ec85
3
+ metadata.gz: 9fdb300c1ddaaf4ab1cfa6ca3e0b1371f4fbf33f1a22f29357bae06da0a973fc
4
+ data.tar.gz: 3c812320dc20d2b9c13bf08e5cff2c596cd873880d8ec5b19b3a0bee68afd875
5
5
  SHA512:
6
- metadata.gz: b8d65f92118b3700b77803005d936a3b1ddee313936207387496d7685bd6361ffcb3fbe6c28bd8c3b5b7fb7d4d1bd1b259e1e898da1b9739df07b99e17e89c1f
7
- data.tar.gz: 398311bc0f57a4722a10d37776aad1a4e0651986a35832fc54a087618fcc3995543a21e35880deaa8ada9b88bfbc91183201c0a8bdf174ebb69ccd34e6233006
6
+ metadata.gz: 83f853427d2f54f0b86d736c1d54e526a74806b643c7d4dc12ea857eeacde38e18b8272374253845e697545168d0afcc9ec48d52fad7c00969d4be972c919b26
7
+ data.tar.gz: 8f463487ca5084e78b11875f3b1d591359c0252055cdd44bb9df06024076b0dc6627647e9d30cd8beaeab1d97ec8b06eb1d986b634513eb5bb8e63184514daad
data/README.md CHANGED
@@ -352,7 +352,7 @@ input = {
352
352
  "status" => ["--verbose|-v", "--branch|-b <branch>"]
353
353
  },
354
354
  "tokens" => {
355
- "directory" => "directory",
355
+ "directory" => "+directory",
356
356
  "branch" => "$(git branch --format='%(refname:short)' 2>/dev/null)"
357
357
  }
358
358
  }
@@ -137,8 +137,10 @@ module Completely
137
137
  end
138
138
  end
139
139
 
140
- def pattern_options_with_values
141
- config.model[:options].values.flatten.select { |option| option[:value] }
140
+ def pattern_has_unique_options?
141
+ pattern_routes.any? do |route|
142
+ pattern_route_options(route).any? { |option| !option[:repeatable] }
143
+ end
142
144
  end
143
145
 
144
146
  def pattern_source_empty?(source)
@@ -4,16 +4,53 @@
4
4
  # completely (https://github.com/bashly-framework/completely)
5
5
  # Modifying it manually is not recommended
6
6
 
7
- <%= function_name %>_flag_expects_value() {
8
- case "$1" in
9
- % pattern_options_with_values.each do |option|
10
- <%= option[:names].map { |name| bash_escape name }.join('|') %>) return 0 ;;
7
+ <%= function_name %>_route_flag_expects_value() {
8
+ case "$1:$2" in
9
+ % pattern_routes.each do |route|
10
+ % pattern_route_options(route).select { |option| option[:value] }.each do |option|
11
+ <%= pattern_route_id route %>:<%= option[:names].map { |name| bash_escape name }.join("|#{pattern_route_id route}:") %>) return 0 ;;
12
+ % end
11
13
  % end
12
14
  esac
13
15
 
14
16
  return 1
15
17
  }
16
18
 
19
+ % if pattern_has_unique_options?
20
+ <%= function_name %>_option_seen() {
21
+ local completed_option option_name
22
+ for completed_option in "${completed_options[@]}"; do
23
+ for option_name in "$@"; do
24
+ [[ "$completed_option" == "$option_name" ]] && return 0
25
+ done
26
+ done
27
+
28
+ return 1
29
+ }
30
+
31
+ % end
32
+ <%= function_name %>_resolve_route() {
33
+ route_id=
34
+ route_word_count=-1
35
+ route_has_positionals=0
36
+ positional_index=0
37
+ % pattern_routes.each do |route|
38
+ % conditions = pattern_route_conditions(route)
39
+ if (( ${#non_options[@]} >= <%= pattern_route_word_count route %> )) &&
40
+ (( <%= pattern_route_word_count route %> > route_word_count ))<%= conditions.empty? ? '' : ' &&' %>
41
+ % conditions.each_with_index do |condition, index|
42
+ [[ <%= condition %> ]]<%= index == conditions.size - 1 ? '' : ' &&' %>
43
+ % end
44
+ then
45
+ route_id=<%= pattern_route_id route %>
46
+ route_word_count=<%= pattern_route_word_count route %>
47
+ route_has_positionals=<%= route[:positionals].empty? ? 0 : 1 %>
48
+ positional_index=$((${#non_options[@]} - <%= pattern_route_word_count route %>))
49
+ fi
50
+
51
+ % end
52
+ }
53
+
17
54
  <%= function_name %>() {
18
55
  local cur=${COMP_WORDS[COMP_CWORD]}
19
56
  local prev=
@@ -28,6 +65,12 @@
28
65
 
29
66
  local non_options=()
30
67
  local completed_options=()
68
+ local route_id=
69
+ local route_word_count=-1
70
+ local route_has_positionals=0
71
+ local positional_index=0
72
+ <%= function_name %>_resolve_route
73
+
31
74
  local skip_next=0
32
75
  for word in "${completed[@]}"; do
33
76
  if ((skip_next)); then
@@ -37,34 +80,16 @@
37
80
 
38
81
  if [[ "${word:0:1}" == "-" ]]; then
39
82
  completed_options+=("$word")
40
- if <%= function_name %>_flag_expects_value "$word"; then
83
+ if <%= function_name %>_route_flag_expects_value "$route_id" "$word"; then
41
84
  skip_next=1
42
85
  fi
43
86
  continue
44
87
  fi
45
88
 
46
89
  non_options+=("$word")
90
+ <%= function_name %>_resolve_route
47
91
  done
48
92
 
49
- local route_id=
50
- local route_word_count=-1
51
- local route_has_positionals=0
52
- local positional_index=0
53
- % pattern_routes.each do |route|
54
- % conditions = pattern_route_conditions(route)
55
- if (( ${#non_options[@]} >= <%= pattern_route_word_count route %> )) &&
56
- (( <%= pattern_route_word_count route %> > route_word_count ))<%= conditions.empty? ? '' : ' &&' %>
57
- % conditions.each_with_index do |condition, index|
58
- [[ <%= condition %> ]]<%= index == conditions.size - 1 ? '' : ' &&' %>
59
- % end
60
- then
61
- route_id=<%= pattern_route_id route %>
62
- route_word_count=<%= pattern_route_word_count route %>
63
- route_has_positionals=<%= route[:positionals].empty? ? 0 : 1 %>
64
- positional_index=$((${#non_options[@]} - <%= pattern_route_word_count route %>))
65
- fi
66
-
67
- % end
68
93
  COMPREPLY=()
69
94
 
70
95
  if [[ -z "$route_id" ]] || { (( route_word_count == 0 )) && (( !route_has_positionals )) && [[ "${cur:0:1}" != "-" ]]; }; then
@@ -96,15 +121,7 @@
96
121
  % if option[:repeatable]
97
122
  words+=(<%= option[:names].map { |name| %["#{bash_escape name}"] }.join(' ') %>)
98
123
  % else
99
- local option_seen=0
100
- for completed_option in "${completed_options[@]}"; do
101
- case "$completed_option" in
102
- <%= option[:names].map { |name| bash_escape name }.join('|') %>) option_seen=1 ;;
103
- esac
104
- done
105
- if ((!option_seen)); then
106
- words+=(<%= option[:names].map { |name| %["#{bash_escape name}"] }.join(' ') %>)
107
- fi
124
+ <%= function_name %>_option_seen <%= option[:names].map { |name| %["#{bash_escape name}"] }.join(' ') %> || words+=(<%= option[:names].map { |name| %["#{bash_escape name}"] }.join(' ') %>)
108
125
  % end
109
126
  % end
110
127
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = '0.8.0.rc3'
2
+ VERSION = '0.8.0.rc5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.rc3
4
+ version: 0.8.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit