Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `cb psql` can take `--database` to specify the name of the database to
connect.
- `cb scope` can take `--database` to specify the name of the database to
connect.

### Fixed
- The --ha flag for `cb create` now actually works

Expand Down
4 changes: 4 additions & 0 deletions spec/cb/completion_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ describe CB::Completion do
result.should have_option "--suite"
result.should have_option "--mandelbrot"
result.should have_option "--tables"
result.should have_option "--database"

result = parse("cb scope --cluster abc --suite ")
result.should have_option "all"
Expand All @@ -362,5 +363,8 @@ describe CB::Completion do
result = parse("cb scope --cluster abc --mandelbrot ")
result.should have_option "--tables"
result.should_not have_option "--mandelbrot"

result = parse("cb scope --cluster abc --database ")
result.should_not have_option "--database"
end
end
21 changes: 20 additions & 1 deletion src/cb/completion.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ class CB::Completion
return top_level
else
case args.first
when "info", "psql", "destroy", "uri"
when "info", "destroy", "uri"
return info
when "create"
return create
when "firewall"
return firewall
when "logdest"
return logdest
when "psql"
return psql
when "teamcert"
return teams
when "scope"
Expand Down Expand Up @@ -283,6 +285,18 @@ class CB::Completion
return suggest
end

def psql
return cluster_suggestions if @args.size == 2

if last_arg?("--database")
[] of String
end

suggest = [] of String
suggest << "--database\tName of database" unless has_full_flag? :database
return suggest
end

def scope
return ["--cluster\tcluster id"] if @args.size == 2

Expand All @@ -294,8 +308,13 @@ class CB::Completion
return ["all\tRun all scopes", "quick\tRun some scopes"]
end

if last_arg?("--database")
[] of String
end

suggest = ::Scope::Check.all.reject { |c| @args.includes? c.flag }.map { |c| "#{c.flag}\t#{c.desc}" }
suggest << "--suite\tRun predefined scopes" unless @args.includes? "--suite"
suggest << "--database\tName of database" unless @args.includes? "--database"

return suggest
end
Expand Down
7 changes: 7 additions & 0 deletions src/cb/psql.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ require "./action"

class CB::Psql < CB::Action
property cluster_id : String?
property database : String?

def run
c = client.get_cluster cluster_id
uri = client.get_cluster_default_role(cluster_id).uri

database.tap { |db| uri.path = db if db }

output << "connecting to "
team_name = print_team_slash_cluster c, output

Expand All @@ -32,6 +35,10 @@ class CB::Psql < CB::Action
@cluster_id = str
end

def database=(str : String)
@database = str
end

private def ensure_cert(team_id) : String
cert_dir = CB::Creds::CONFIG / "certs"
path = cert_dir / "#{team_id}.pem"
Expand Down
9 changes: 9 additions & 0 deletions src/cb/scope.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ require "./scope_checks/*"
class CB::Scope < CB::Action
property cluster_id : String?
property checks : Array(::Scope::Check.class) = [] of ::Scope::Check.class
property database : String?
property suite : String?

def run
check_required_args { |missing| missing << "cluster" unless cluster_id }

uri = client.get_cluster_default_role(cluster_id).uri

if database.presence
uri.path = database.to_s
end

self.suite = "quick" if checks.empty? && suite.nil?

case suite
Expand All @@ -32,3 +37,7 @@ class CB::Scope < CB::Action
end
end
end

def database=(str : String)
@database = str
end
5 changes: 4 additions & 1 deletion src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ op = OptionParser.new do |parser|
end

parser.on("psql", "Connect to the database using `psql`") do
parser.banner = "Usage: cb psql <cluster id> [-- [args for psql such as -c or -f]]"
parser.banner = "Usage: cb psql <cluster id> [--database] [-- [args for psql such as -c or -f]]"
action = psql = CB::Psql.new(PROG.client)

parser.on("--database NAME", "Database name (default: postgres)") { |arg| psql.database = arg }

parser.unknown_args do |args|
psql.cluster_id = get_id_arg.call(args)
end
Expand Down Expand Up @@ -129,6 +131,7 @@ op = OptionParser.new do |parser|
action = scope = CB::Scope.new PROG.client
parser.on("--cluster ID", "Choose cluster") { |arg| scope.cluster_id = arg }
parser.on("--suite <all|quick>", "Run suite of scopes (default: quick)") { |arg| scope.suite = arg }
parser.on("--database NAME", "Database name (default: postgres)") { |arg| scope.database = arg }
Scope::Check.all.each do |ck|
parser.on(ck.flag, ck.desc) { scope.checks << ck.type }
end
Expand Down