deploio-cli 0.2.0 → 0.4.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.
@@ -0,0 +1,140 @@
1
+ # Bash completion for <%= program_name %>-cli
2
+ # Auto-generated from Thor command definitions
3
+ # Enable with: eval "$(<%= program_name %> completion --shell bash)"
4
+
5
+ # Dynamic completion for organizations
6
+ _<%= program_name %>_orgs_list() {
7
+ <%= program_name %> orgs --json 2>/dev/null | ruby -rjson -e '
8
+ data = JSON.parse(STDIN.read) rescue []
9
+ data.each { |o| puts o["name"] }
10
+ ' 2>/dev/null
11
+ }
12
+
13
+ # Dynamic completion for projects
14
+ _<%= program_name %>_projects_list() {
15
+ <%= program_name %> projects --json 2>/dev/null | ruby -rjson -e '
16
+ data = JSON.parse(STDIN.read) rescue []
17
+ orgs_json = `<%= program_name %> orgs --json 2>/dev/null` rescue "[]"
18
+ orgs = JSON.parse(orgs_json) rescue []
19
+ current_org = orgs.find { |o| o["current"] }&.fetch("name", nil)
20
+
21
+ data.each do |p|
22
+ name = p.dig("metadata", "name") || ""
23
+ short_name = current_org && name.start_with?("#{current_org}-") ? name.delete_prefix("#{current_org}-") : name
24
+ puts short_name
25
+ end
26
+ ' 2>/dev/null
27
+ }
28
+
29
+ # Dynamic completion for apps
30
+ _<%= program_name %>_apps_list() {
31
+ <%= program_name %> apps --json 2>/dev/null | ruby -rjson -e '
32
+ data = JSON.parse(STDIN.read) rescue []
33
+ orgs_json = `<%= program_name %> orgs --json 2>/dev/null` rescue "[]"
34
+ orgs = JSON.parse(orgs_json) rescue []
35
+ current_org = orgs.find { |o| o["current"] }&.fetch("name", nil)
36
+
37
+ data.each do |a|
38
+ ns = a.dig("metadata", "namespace") || ""
39
+ name = a.dig("metadata", "name") || ""
40
+ project = current_org && ns.start_with?("#{current_org}-") ? ns.delete_prefix("#{current_org}-") : ns
41
+ puts "#{project}-#{name}"
42
+ end
43
+ ' 2>/dev/null
44
+ }
45
+
46
+ # Dynamic completion for PostgreSQL databases
47
+ _<%= program_name %>_pg_databases_list() {
48
+ <%= program_name %> pg list --json 2>/dev/null | ruby -rjson -e '
49
+ data = JSON.parse(STDIN.read) rescue []
50
+ orgs_json = `<%= program_name %> orgs --json 2>/dev/null` rescue "[]"
51
+ orgs = JSON.parse(orgs_json) rescue []
52
+ current_org = orgs.find { |o| o["current"] }&.fetch("name", nil)
53
+
54
+ data.each do |db|
55
+ ns = db.dig("metadata", "namespace") || ""
56
+ name = db.dig("metadata", "name") || ""
57
+ project = current_org && ns.start_with?("#{current_org}-") ? ns.delete_prefix("#{current_org}-") : ns
58
+ puts "#{project}-#{name}"
59
+ end
60
+ ' 2>/dev/null
61
+ }
62
+
63
+ # Sets the candidates following a command path in the caller's scope
64
+ _<%= program_name %>_context() {
65
+ commands="" flags="" value_flags="" positional="" passthrough=""
66
+ case "$1" in
67
+ <% contexts.each do |context| -%>
68
+ "<%= context.path %>")
69
+ <% unless context.commands.empty? -%>
70
+ commands="<%= context.commands.join(" ") %>"
71
+ <% end -%>
72
+ flags="<%= flags(context).join(" ") %>"
73
+ <% unless value_flags(context).empty? -%>
74
+ value_flags="<%= value_flags(context).join(" ") %>"
75
+ <% end -%>
76
+ <% if context.positional -%>
77
+ positional="<%= context.positional %>"
78
+ <% end -%>
79
+ <% if context.passthrough -%>
80
+ passthrough=1
81
+ <% end -%>
82
+ ;;
83
+ <% end -%>
84
+ esac
85
+ }
86
+
87
+ _<%= program_name %>_option_values() {
88
+ case "$1" in
89
+ <% option_value_completers.each do |flags, completer| -%>
90
+ <%= flags.join("|") %>) <%= completer %> ;;
91
+ <% end -%>
92
+ esac
93
+ }
94
+
95
+ _<%= program_name %>_includes() {
96
+ [[ -n "$2" && " $1 " == *" $2 "* ]]
97
+ }
98
+
99
+ # Main completion function
100
+ _<%= program_name %>() {
101
+ local cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
102
+ local cmd="" args=0 word i
103
+ local commands flags value_flags positional passthrough
104
+ COMPREPLY=()
105
+
106
+ _<%= program_name %>_context ""
107
+ for ((i = 1; i < COMP_CWORD; i++)); do
108
+ word="${COMP_WORDS[i]}"
109
+ if [[ "$word" == "--" && -n "$passthrough" ]]; then
110
+ if ((i + 1 == COMP_CWORD)); then
111
+ COMPREPLY=($(compgen -c -- "$cur"))
112
+ else
113
+ COMPREPLY=($(compgen -f -- "$cur"))
114
+ fi
115
+ return
116
+ elif _<%= program_name %>_includes "$value_flags" "$word"; then
117
+ ((++i))
118
+ elif [[ "$word" == -* ]]; then
119
+ continue
120
+ elif ((args == 0)) && _<%= program_name %>_includes "$commands" "$word"; then
121
+ cmd="${cmd:+$cmd:}$word"
122
+ _<%= program_name %>_context "$cmd"
123
+ else
124
+ ((++args))
125
+ fi
126
+ done
127
+
128
+ if _<%= program_name %>_includes "$value_flags" "$prev"; then
129
+ COMPREPLY=($(compgen -W "$(_<%= program_name %>_option_values "$prev")" -- "$cur"))
130
+ elif [[ "$cur" == -* ]]; then
131
+ COMPREPLY=($(compgen -W "$flags" -- "$cur"))
132
+ elif ((args == 0)) && [[ -n "$commands" ]]; then
133
+ COMPREPLY=($(compgen -W "$commands" -- "$cur"))
134
+ elif ((args == 0)) && [[ -n "$positional" ]]; then
135
+ COMPREPLY=($(compgen -W "$($positional)" -- "$cur"))
136
+ fi
137
+ }
138
+
139
+ # Register the completion function
140
+ complete -F _<%= program_name %> <%= program_name %> depl
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deploio
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/deploio.rb CHANGED
@@ -7,9 +7,16 @@ require_relative "deploio/utils"
7
7
  require_relative "deploio/output"
8
8
  require_relative "deploio/app_ref"
9
9
  require_relative "deploio/pg_database_ref"
10
+ require_relative "deploio/mysql_database_ref"
10
11
  require_relative "deploio/nctl_client"
12
+ require_relative "deploio/rclone_client"
11
13
  require_relative "deploio/app_resolver"
12
14
  require_relative "deploio/pg_database_resolver"
15
+ require_relative "deploio/postgres_backup_service"
16
+ require_relative "deploio/postgres_database_backup_service"
17
+ require_relative "deploio/mysql_database_resolver"
18
+ require_relative "deploio/mysql_backup_service"
19
+ require_relative "deploio/mysql_database_backup_service"
13
20
  require_relative "deploio/price_fetcher"
14
21
  require_relative "deploio/shared_options"
15
22
  require_relative "deploio/cli"
@@ -18,5 +25,8 @@ module Deploio
18
25
  class Error < StandardError; end
19
26
  class AppNotFoundError < Error; end
20
27
  class PgDatabaseNotFoundError < Error; end
28
+ class MysqlDatabaseNotFoundError < Error; end
21
29
  class NctlError < Error; end
30
+ class RcloneError < Error; end
31
+ class UnsupportedBackupOperationError < Error; end
22
32
  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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renuo AG
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".ruby-version"
49
+ - CHANGELOG.md
49
50
  - README.md
50
51
  - Rakefile
51
52
  - bin/deploio
@@ -53,31 +54,41 @@ files:
53
54
  - lib/deploio.rb
54
55
  - lib/deploio/app_ref.rb
55
56
  - lib/deploio/app_resolver.rb
57
+ - lib/deploio/bash_completion_generator.rb
56
58
  - lib/deploio/cli.rb
57
59
  - lib/deploio/commands/apps.rb
58
60
  - lib/deploio/commands/auth.rb
59
61
  - lib/deploio/commands/builds.rb
62
+ - lib/deploio/commands/mysql.rb
63
+ - lib/deploio/commands/mysql_backups.rb
60
64
  - lib/deploio/commands/orgs.rb
61
65
  - lib/deploio/commands/postgresql.rb
62
66
  - lib/deploio/commands/postgresql_backups.rb
63
67
  - lib/deploio/commands/projects.rb
64
68
  - lib/deploio/commands/services.rb
65
69
  - lib/deploio/completion_generator.rb
70
+ - lib/deploio/helpers/backups_helper.rb
71
+ - lib/deploio/mysql_backup_service.rb
72
+ - lib/deploio/mysql_database_backup_service.rb
73
+ - lib/deploio/mysql_database_ref.rb
74
+ - lib/deploio/mysql_database_resolver.rb
66
75
  - lib/deploio/nctl_client.rb
67
76
  - lib/deploio/output.rb
68
77
  - lib/deploio/pg_database_ref.rb
69
78
  - lib/deploio/pg_database_resolver.rb
79
+ - lib/deploio/postgres_backup_service.rb
80
+ - lib/deploio/postgres_database_backup_service.rb
70
81
  - lib/deploio/price_fetcher.rb
82
+ - lib/deploio/rclone_client.rb
71
83
  - lib/deploio/shared_options.rb
84
+ - lib/deploio/templates/completion.bash.erb
72
85
  - lib/deploio/templates/completion.zsh.erb
73
86
  - lib/deploio/utils.rb
74
87
  - lib/deploio/version.rb
75
- - setup
76
88
  homepage: https://github.com/renuo/deploio-cli
77
89
  licenses:
78
90
  - MIT
79
91
  metadata:
80
- homepage_uri: https://github.com/renuo/deploio-cli
81
92
  source_code_uri: https://github.com/renuo/deploio-cli
82
93
  changelog_uri: https://github.com/renuo/deploio-cli/blob/main/CHANGELOG.md
83
94
  post_install_message: |+
@@ -85,6 +96,10 @@ post_install_message: |+
85
96
 
86
97
  eval "$(deploio completion)"
87
98
 
99
+ or this to your ~/.bashrc:
100
+
101
+ eval "$(deploio completion --shell bash)"
102
+
88
103
  rdoc_options: []
89
104
  require_paths:
90
105
  - lib
data/setup DELETED
@@ -1,115 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- APP_NAME=${APP_NAME:-deploio}
4
- INSTALL_DIR=${INSTALL_DIR:-"${HOME}/.local/bin"}
5
- RAW_BASE=${RAW_BASE:-"https://raw.githubusercontent.com/CuddlyBunion341/deploio-cli/main"}
6
- CLI_URL="${RAW_BASE}/deploio"
7
- MAN_URL="${RAW_BASE}/deploio.1"
8
- COMPLETION_URL="${RAW_BASE}/_deploio"
9
- COLOR_RESET='\033[0m'
10
- COLOR_GREEN='\033[0;32m'
11
- COLOR_YELLOW='\033[0;33m'
12
- COLOR_CYAN='\033[0;36m'
13
- COLOR_RED='\033[0;31m'
14
- print() { printf "%b\n" "$*"; }
15
- info() { print "${COLOR_CYAN}$*${COLOR_RESET}"; }
16
- success() { print "${COLOR_GREEN}$*${COLOR_RESET}"; }
17
- warn() { print "${COLOR_YELLOW}$*${COLOR_RESET}"; }
18
- err() { print "${COLOR_RED}$*${COLOR_RESET}" 1>&2; }
19
- have_cmd() { command -v "$1" >/dev/null 2>&1; }
20
- fetch() {
21
- local url="$1" dest="$2"
22
- if have_cmd curl; then
23
- curl -fsSL "$url" -o "$dest"
24
- elif have_cmd wget; then
25
- wget -qO "$dest" "$url"
26
- else
27
- err "Need curl or wget to download: $url"
28
- return 1
29
- fi
30
- }
31
- main() {
32
- info "Installing ${APP_NAME} (deplo.io app CLI)"
33
- mkdir -p "$INSTALL_DIR"
34
- tmp_file="$(mktemp -t ${APP_NAME}.XXXXXX)"
35
- tmp_man="$(mktemp -t ${APP_NAME}-man.XXXXXX)"
36
- tmp_completion="$(mktemp -t ${APP_NAME}-completion.XXXXXX)"
37
- trap 'rm -f "$tmp_file" "$tmp_man" "$tmp_completion"' EXIT
38
-
39
- info "Downloading CLI from: $CLI_URL"
40
- if ! fetch "$CLI_URL" "$tmp_file"; then
41
- err "Failed to download ${APP_NAME} from $CLI_URL"
42
- exit 1
43
- fi
44
-
45
- info "Downloading man page from: $MAN_URL"
46
- if ! fetch "$MAN_URL" "$tmp_man"; then
47
- warn "Failed to download man page from $MAN_URL (continuing without man page)"
48
- fi
49
-
50
- info "Downloading zsh completion from: $COMPLETION_URL"
51
- if ! fetch "$COMPLETION_URL" "$tmp_completion"; then
52
- warn "Failed to download completion script from $COMPLETION_URL (continuing without completions)"
53
- fi
54
-
55
- install_path="${INSTALL_DIR}/${APP_NAME}"
56
- mv "$tmp_file" "$install_path"
57
- chmod +x "$install_path"
58
-
59
- # Install man page if download succeeded
60
- if [[ -s "$tmp_man" ]]; then
61
- man_dir="${HOME}/.local/share/man/man1"
62
- mkdir -p "$man_dir"
63
- mv "$tmp_man" "${man_dir}/${APP_NAME}.1"
64
- success "Installed man page to ${man_dir}/${APP_NAME}.1"
65
- fi
66
-
67
- # Install zsh completion if download succeeded
68
- if [[ -s "$tmp_completion" ]]; then
69
- completion_dir="${HOME}/.local/share/zsh/site-functions"
70
- mkdir -p "$completion_dir"
71
- mv "$tmp_completion" "${completion_dir}/_${APP_NAME}"
72
- success "Installed zsh completion to ${completion_dir}/_${APP_NAME}"
73
- fi
74
-
75
- # Create shorthand symlink 'depl'
76
- (cd "$INSTALL_DIR" && ln -sf "$APP_NAME" depl)
77
- success "Installed ${APP_NAME} to ${install_path}"
78
- case ":${PATH}:" in
79
- *":${INSTALL_DIR}:"*) ;;
80
- *)
81
- warn "${INSTALL_DIR} is not on your PATH. Add this to your ~/.zshrc:"
82
- echo ""
83
- echo " export PATH=\"$INSTALL_DIR:\$PATH\""
84
- echo ""
85
- echo "Then reload your shell:"
86
- echo " source ~/.zshrc"
87
- ;;
88
- esac
89
-
90
- # Check if man page directory is in MANPATH
91
- man_dir="${HOME}/.local/share/man"
92
- if [[ -f "${man_dir}/man1/${APP_NAME}.1" ]] && [[ ":${MANPATH}:" != *":${man_dir}:"* ]]; then
93
- warn "Man page installed but ${man_dir} is not in MANPATH."
94
- echo "Add this to your ~/.zshrc to access man pages:"
95
- echo ""
96
- echo " export MANPATH=\"${man_dir}:\$MANPATH\""
97
- echo ""
98
- fi
99
-
100
- # Check if completion directory is in fpath
101
- completion_dir="${HOME}/.local/share/zsh/site-functions"
102
- if [[ -f "${completion_dir}/_${APP_NAME}" ]]; then
103
- echo "Zsh completion installed. To enable it, add this to your ~/.zshrc:"
104
- echo ""
105
- echo " fpath=(\"${completion_dir}\" \$fpath)"
106
- echo " autoload -Uz compinit && compinit"
107
- echo ""
108
- echo "Then restart your shell or run: source ~/.zshrc"
109
- fi
110
- echo ""
111
- info "Test the installation:"
112
- echo " ${APP_NAME} --dry-run list"
113
- echo " man ${APP_NAME}"
114
- }
115
- main "$@"