deploio-cli 0.1.1 → 0.3.0

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.
@@ -23,6 +23,58 @@ _<%= program_name %>_orgs_list() {
23
23
  fi
24
24
  }
25
25
 
26
+ # Dynamic completion for services
27
+ _<%= program_name %>_services_list() {
28
+ local -a services
29
+ services=(${(f)"$(<%= program_name %> services --json 2>/dev/null | ruby -rjson -e '
30
+ data = JSON.parse(STDIN.read) rescue []
31
+ orgs_json = `<%= program_name %> orgs --json 2>/dev/null` rescue "[]"
32
+ orgs = JSON.parse(orgs_json) rescue []
33
+ current_org = orgs.find { |o| o["current"] }&.fetch("name", nil)
34
+
35
+ data.each do |s|
36
+ ns = s.dig("metadata", "namespace") || ""
37
+ name = s.dig("metadata", "name") || ""
38
+ type = s["_type"] || "unknown"
39
+ project = current_org && ns.start_with?("#{current_org}-") ? ns.delete_prefix("#{current_org}-") : ns
40
+ short_name = "#{project}-#{name}"
41
+ puts "#{short_name}:#{name} (#{type})"
42
+ end
43
+ ' 2>/dev/null)"})
44
+
45
+ if [[ ${#services[@]} -gt 0 ]]; then
46
+ _describe -t services 'available services' services
47
+ else
48
+ _message 'service (format: project-servicename)'
49
+ fi
50
+ }
51
+
52
+ # Dynamic completion for projects
53
+ _<%= program_name %>_projects_list() {
54
+ local -a projects
55
+ projects=(${(f)"$(<%= program_name %> projects --json 2>/dev/null | ruby -rjson -e '
56
+ data = JSON.parse(STDIN.read) rescue []
57
+ orgs_json = `<%= program_name %> orgs --json 2>/dev/null` rescue "[]"
58
+ orgs = JSON.parse(orgs_json) rescue []
59
+ current_org = orgs.find { |o| o["current"] }&.fetch("name", nil)
60
+
61
+ data.each do |p|
62
+ name = p.dig("metadata", "name") || ""
63
+ display_name = p.dig("spec", "displayName").to_s
64
+ # Strip org prefix from project name for short name
65
+ short_name = current_org && name.start_with?("#{current_org}-") ? name.delete_prefix("#{current_org}-") : name
66
+ label = display_name.length > 0 ? display_name : short_name
67
+ puts "#{short_name}:#{label}"
68
+ end
69
+ ' 2>/dev/null)"})
70
+
71
+ if [[ ${#projects[@]} -gt 0 ]]; then
72
+ _describe -t projects 'available projects' projects
73
+ else
74
+ _message 'project name'
75
+ fi
76
+ }
77
+
26
78
  # Dynamic completion for apps
27
79
  _<%= program_name %>_apps_list() {
28
80
  local -a apps
@@ -48,7 +100,37 @@ _<%= program_name %>_apps_list() {
48
100
  fi
49
101
  }
50
102
 
51
- <% subcommands.each do |name, commands, class_options| %>
103
+ # Dynamic completion for PostgreSQL databases
104
+ _<%= program_name %>_pg_databases_list() {
105
+ local -a databases
106
+ databases=(${(f)"$(<%= program_name %> pg list --json 2>/dev/null | ruby -rjson -e '
107
+ data = JSON.parse(STDIN.read) rescue []
108
+ orgs_json = `<%= program_name %> orgs --json 2>/dev/null` rescue "[]"
109
+ orgs = JSON.parse(orgs_json) rescue []
110
+ current_org = orgs.find { |o| o["current"] }&.fetch("name", nil)
111
+
112
+ data.each do |db|
113
+ metadata = db["metadata"] || {}
114
+ spec = db["spec"] || {}
115
+ for_provider = spec["forProvider"] || {}
116
+ ns = metadata["namespace"] || ""
117
+ name = metadata["name"] || ""
118
+ version = for_provider["version"] || "?"
119
+ kind = db["kind"] || ""
120
+ project = current_org && ns.start_with?("#{current_org}-") ? ns.delete_prefix("#{current_org}-") : ns
121
+ short_name = "#{project}-#{name}"
122
+ puts "#{short_name}:#{name} (#{kind}, v#{version})"
123
+ end
124
+ ' 2>/dev/null)"})
125
+
126
+ if [[ ${#databases[@]} -gt 0 ]]; then
127
+ _describe -t databases 'available PostgreSQL databases' databases
128
+ else
129
+ _message 'database (format: project-dbname)'
130
+ fi
131
+ }
132
+
133
+ <% subcommands.each do |name, commands, class_options, default_task, klass| %>
52
134
  # <%= name %> subcommand
53
135
  _<%= program_name %>_<%= name %>() {
54
136
  local -a <%= name %>_commands
@@ -58,6 +140,20 @@ _<%= program_name %>_<%= name %>() {
58
140
  <% end -%>
59
141
  )
60
142
 
143
+ <% default_cmd = commands.find { |cmd_name, _, _| cmd_name == default_task } -%>
144
+ <% if default_cmd -%>
145
+ # Handle options directly (for default task) or subcommand
146
+ # Check if current word or next word after subcommand starts with -
147
+ local first_arg="${words[2]}"
148
+ local current_word="${words[CURRENT]}"
149
+ if [[ "$first_arg" == -* ]] || [[ "$current_word" == -* ]] || [[ -z "$first_arg" && "$current_word" == -* ]]; then
150
+ # Options provided directly - use default task (<%= default_task %>)
151
+ _arguments -s \
152
+ <%= format_options(default_cmd[2], class_options, positional_arg(name, default_task)) %>
153
+ return
154
+ fi
155
+
156
+ <% end -%>
61
157
  _arguments -s \
62
158
  '1:<%= name %> command:-><%= name %>_cmd' \
63
159
  '*::<%= name %> args:-><%= name %>_args'
@@ -70,8 +166,45 @@ _<%= program_name %>_<%= name %>() {
70
166
  case "$words[1]" in
71
167
  <% commands.each do |cmd_name, _, options| -%>
72
168
  <%= cmd_name %>)
169
+ <% if klass.subcommand_classes.key?(cmd_name) -%>
170
+ _<%= program_name %>_<%= name %>_<%= cmd_name %>
171
+ <% else -%>
73
172
  _arguments -s \
74
173
  <%= format_options(options, class_options, positional_arg(name, cmd_name)) %>
174
+ <% end -%>
175
+ ;;
176
+ <% end -%>
177
+ esac
178
+ ;;
179
+ esac
180
+ }
181
+ <% end %>
182
+
183
+ <% nested_subcommands.each do |full_name, commands, class_options| %>
184
+ <% parent_name, nested_name = full_name.split(':') %>
185
+ # <%= full_name %> nested subcommand
186
+ _<%= program_name %>_<%= parent_name %>_<%= nested_name %>() {
187
+ local -a <%= nested_name %>_commands
188
+ <%= nested_name %>_commands=(
189
+ <% commands.each do |cmd_name, desc| -%>
190
+ '<%= cmd_name %>:<%= escape(desc) %>'
191
+ <% end -%>
192
+ )
193
+
194
+ _arguments -s \
195
+ '1:<%= nested_name %> command:-><%= nested_name %>_cmd' \
196
+ '*::<%= nested_name %> args:-><%= nested_name %>_args'
197
+
198
+ case "$state" in
199
+ <%= nested_name %>_cmd)
200
+ _describe -t commands '<%= nested_name %> commands' <%= nested_name %>_commands
201
+ ;;
202
+ <%= nested_name %>_args)
203
+ case "$words[1]" in
204
+ <% commands.each do |cmd_name, _, options| -%>
205
+ <%= cmd_name %>)
206
+ _arguments -s \
207
+ <%= format_options(options, class_options, positional_arg(full_name, cmd_name)) %>
75
208
  ;;
76
209
  <% end -%>
77
210
  esac
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deploio
4
- VERSION = "0.1.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/deploio.rb CHANGED
@@ -6,13 +6,22 @@ require_relative "deploio/version"
6
6
  require_relative "deploio/utils"
7
7
  require_relative "deploio/output"
8
8
  require_relative "deploio/app_ref"
9
+ require_relative "deploio/pg_database_ref"
9
10
  require_relative "deploio/nctl_client"
11
+ require_relative "deploio/rclone_client"
10
12
  require_relative "deploio/app_resolver"
13
+ require_relative "deploio/pg_database_resolver"
14
+ require_relative "deploio/postgres_backup_service"
15
+ require_relative "deploio/postgres_database_backup_service"
16
+ require_relative "deploio/price_fetcher"
11
17
  require_relative "deploio/shared_options"
12
18
  require_relative "deploio/cli"
13
19
 
14
20
  module Deploio
15
21
  class Error < StandardError; end
16
22
  class AppNotFoundError < Error; end
23
+ class PgDatabaseNotFoundError < Error; end
17
24
  class NctlError < Error; end
25
+ class RcloneError < Error; end
26
+ class UnsupportedBackupOperationError < Error; end
18
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploio-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renuo AG
@@ -56,10 +56,21 @@ files:
56
56
  - lib/deploio/cli.rb
57
57
  - lib/deploio/commands/apps.rb
58
58
  - lib/deploio/commands/auth.rb
59
+ - lib/deploio/commands/builds.rb
59
60
  - lib/deploio/commands/orgs.rb
61
+ - lib/deploio/commands/postgresql.rb
62
+ - lib/deploio/commands/postgresql_backups.rb
63
+ - lib/deploio/commands/projects.rb
64
+ - lib/deploio/commands/services.rb
60
65
  - lib/deploio/completion_generator.rb
61
66
  - lib/deploio/nctl_client.rb
62
67
  - lib/deploio/output.rb
68
+ - lib/deploio/pg_database_ref.rb
69
+ - lib/deploio/pg_database_resolver.rb
70
+ - lib/deploio/postgres_backup_service.rb
71
+ - lib/deploio/postgres_database_backup_service.rb
72
+ - lib/deploio/price_fetcher.rb
73
+ - lib/deploio/rclone_client.rb
63
74
  - lib/deploio/shared_options.rb
64
75
  - lib/deploio/templates/completion.zsh.erb
65
76
  - lib/deploio/utils.rb
@@ -91,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
102
  - !ruby/object:Gem::Version
92
103
  version: '0'
93
104
  requirements: []
94
- rubygems_version: 4.0.3
105
+ rubygems_version: 3.6.9
95
106
  specification_version: 4
96
107
  summary: CLI for Deploio
97
108
  test_files: []