Skip to content

Commit

Permalink
Add multiple format options
Browse files Browse the repository at this point in the history
  • Loading branch information
fdr authored and abrightwell committed May 26, 2022
1 parent 8f8f52b commit bbd4e67
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions spec/cb/completion_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ describe CB::Completion do
result.should eq ["abc\tmy team/my cluster"]
result = parse("cb backup token abc ")
result.should_not have_option "abc"
result.should have_option "--format"
result = parse("cb backup token abc --format ")
result.should eq ["default", "pgbackrest"]
end

it "completes detach" do
Expand Down
36 changes: 36 additions & 0 deletions src/cb/backup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module CB

class BackupToken < Action
eid_setter cluster_id
ident_setter format

def run
check_required_args do |missing|
Expand All @@ -107,6 +108,17 @@ module CB
"No Credentials"
end

case @format
when nil, "default"
output_default(token, cred)
when "pgbackrest"
output_pgbackrest(token, cred)
else
raise Error.new("invalid format #{@format}")
end
end

def output_default(token, cred)
output << "Type:".colorize.bold << " #{token.type}\n"
output << "Repo Path:".colorize.bold << " #{token.repo_path}\n"
if cred.is_a?(Client::AWSBackrestCredential)
Expand All @@ -124,5 +136,29 @@ module CB
output << cred << '\n'
end
end

def output_pgbackrest(token, cred)
output << "repo1-type=#{token.type}\n"
output << "repo1-path=#{token.repo_path}"
if cred.is_a?(Client::AWSBackrestCredential)
output << <<-AWS
repo1-s3-bucket=#{cred.s3_bucket}
repo1-s3-key=#{cred.s3_key}
repo1-s3-key-secret=#{cred.s3_key_secret}
repo1-s3-token=#{cred.s3_token}
repo1-s3-endpoint=s3.dualstack.#{cred.s3_region}.amazonaws.com
repo1-s3-region=#{cred.s3_region}
AWS
elsif cred.is_a?(Client::AzureBackrestCredential)
output << <<-AZURE
repo1-azure-account=#{cred.azure_account}
repo1-azure-container=#{cred.azure_container}
repo1-azure-key-type=#{cred.azure_key_type}
repo1-azure-key=#{cred.azure_key}
AZURE
else
output << cred << '\n'
end
end
end
end
16 changes: 15 additions & 1 deletion src/cb/completion.cr
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,26 @@ class CB::Completion
"capture\tstart a new backup",
"token\tcreate a backup token",
]
when "list", "capture", "token"
when "list", "capture"
return cluster_suggestions if @args.size == 3
when "token"
return cluster_suggestions if @args.size == 3
return backup_token
end

suggest_none
end

def backup_token
if last_arg?("--format")
return ["default", "pgbackrest"]
end

suggest = [] of String
suggest << "--format\toutput format" unless has_full_flag? :format
suggest
end

#
# Team Completion.
#
Expand Down Expand Up @@ -787,6 +800,7 @@ class CB::Completion
full << :account if has_full_flag? "--account"
full << :email if has_full_flag? "--email"
full << :full if has_full_flag? "--full"
full << :format if has_full_flag? "--format"
full
end

Expand Down
1 change: 1 addition & 0 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ op = OptionParser.new do |parser|

parser.on("token", "Create backup token") do
token = set_action BackupToken
parser.on("--format=FORMAT", "<default|pgbackrest>") { |arg| token.format = arg }
parser.banner = "cb backup token <cluster id>"
parser.unknown_args { |args| token.cluster_id = get_id_arg.call(args) }
end
Expand Down

0 comments on commit bbd4e67

Please sign in to comment.