Add -p, --path to connect|disconnect commands

This commit is contained in:
0x1eef 2024-04-25 02:43:58 -03:00
parent a34c48b26c
commit 527dff3497
2 changed files with 16 additions and 5 deletions

View file

@ -3,6 +3,8 @@
class Twenty::Command::Connect < Twenty::Command class Twenty::Command::Connect < Twenty::Command
set_banner usage: "twenty connect [OPTIONS]", set_banner usage: "twenty connect [OPTIONS]",
description: "Connect a project to twenty" description: "Connect a project to twenty"
set_option "-p PATH", "--path PATH", "The path to a project", default: nil
prepend Twenty::Command::MigrationMixin prepend Twenty::Command::MigrationMixin
prepend Twenty::Command::SQLiteMixin prepend Twenty::Command::SQLiteMixin
prepend Twenty::Command::RescueMixin prepend Twenty::Command::RescueMixin
@ -15,9 +17,15 @@ class Twenty::Command::Connect < Twenty::Command
private private
def run_command(options) def run_command(options)
Twenty::Project.create( path = options.path ? File.expand_path(options.path) : Dir.getwd
name: File.basename(Dir.getwd), if File.exist?(path)
path: Dir.getwd project = Twenty::Project.create(
name: File.basename(path),
path:,
) )
warn "[-] '#{project.name}' connected"
else
abort "[x] The path (#{path}) does not exist"
end
end end
end end

View file

@ -3,6 +3,7 @@
class Twenty::Command::Disconnect < Twenty::Command class Twenty::Command::Disconnect < Twenty::Command
set_banner usage: "twenty disconnect [OPTIONS]", set_banner usage: "twenty disconnect [OPTIONS]",
description: "Disconnect a project from twenty" description: "Disconnect a project from twenty"
set_option "-p PATH", "--path PATH", "The path to a project", default: nil
prepend Twenty::Command::MigrationMixin prepend Twenty::Command::MigrationMixin
prepend Twenty::Command::SQLiteMixin prepend Twenty::Command::SQLiteMixin
prepend Twenty::Command::RescueMixin prepend Twenty::Command::RescueMixin
@ -15,9 +16,11 @@ class Twenty::Command::Disconnect < Twenty::Command
private private
def run_command(options) def run_command(options)
path = options.path ? File.expand_path(options.path) : Dir.getwd
Twenty::Project Twenty::Project
.where(path: Dir.getwd) .where(path:)
.first! .first!
.destroy .destroy
warn "[-] '#{File.basename(path)}' disconnected"
end end
end end