"bundle exec twenty connect" works
This commit is contained in:
parent
b23d7fbe4d
commit
ba559e1dbc
2 changed files with 47 additions and 3 deletions
|
@ -1,4 +1,36 @@
|
||||||
module Twenty
|
module Twenty
|
||||||
|
module DB
|
||||||
|
require "json"
|
||||||
|
DEFAULTS = { connections: [] }
|
||||||
|
|
||||||
|
##
|
||||||
|
# FIXME:
|
||||||
|
# The following methods are required by
|
||||||
|
# both twenty-cli, and twenty-backend. Eventually
|
||||||
|
# they should be moved into their own package.
|
||||||
|
|
||||||
|
extend self
|
||||||
|
|
||||||
|
def home
|
||||||
|
File.join Dir.home, ".local", "share", "twenty"
|
||||||
|
end
|
||||||
|
|
||||||
|
def database
|
||||||
|
Ryo.from DEFAULTS.dup.merge(JSON.parse(database_path))
|
||||||
|
rescue
|
||||||
|
Ryo.from(DEFAULTS.dup)
|
||||||
|
end
|
||||||
|
|
||||||
|
def database_path
|
||||||
|
File.join(home, "database.json")
|
||||||
|
end
|
||||||
|
|
||||||
|
def save!(db)
|
||||||
|
File.binwrite database_path,
|
||||||
|
JSON.dump(Ryo.table_of(db, recursive: true))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
require "twenty/backend"
|
require "twenty/backend"
|
||||||
require "twenty/frontend"
|
require "twenty/frontend"
|
||||||
require_relative "command"
|
require_relative "command"
|
||||||
|
|
|
@ -1,15 +1,27 @@
|
||||||
class Twenty::Command::Connect < Twenty::Command
|
class Twenty::Command::Connect < Twenty::Command
|
||||||
|
require "fileutils"
|
||||||
|
include Twenty::DB
|
||||||
|
include FileUtils
|
||||||
|
|
||||||
set_banner usage: "twenty connect [OPTIONS]",
|
set_banner usage: "twenty connect [OPTIONS]",
|
||||||
description: "Connect a project to twenty"
|
description: "Connect a project to twenty"
|
||||||
|
|
||||||
def run
|
def run
|
||||||
options = parse_options(argv)
|
options = parse_options(argv)
|
||||||
options.help ? show_help : run_command
|
options.help ? show_help : run_command(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def run_command
|
def run_command(options)
|
||||||
warn "[twenty] connect..."
|
mkdir_p File.dirname(database_path)
|
||||||
|
path = Dir.getwd
|
||||||
|
name = File.basename(path)
|
||||||
|
db.connections.push({name:, path:})
|
||||||
|
save!(db)
|
||||||
|
end
|
||||||
|
|
||||||
|
def db
|
||||||
|
@db ||= database
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue