twenty-cli 0.5.4 → 0.5.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a07dbee307b110c4d96b36254fafff8432eb57388c74748f84985b5b0f452fc
4
- data.tar.gz: 8badd46d8d4bfe53955082e4e94b87f14f6f9d466ffc7bb3b46e3db835025595
3
+ metadata.gz: 2788338657a1baa50cd9df1dbf6f0ee6cec4670c70e888d0ecf483c2dee42aec
4
+ data.tar.gz: b1cc4f163fc1a2be7aeb924ab9bbfba5f4769d4d848fe78265b288fb77e14dc3
5
5
  SHA512:
6
- metadata.gz: e9291a9992e134f1fa5872162d053d9be7402810515c020593c89dd2545b1ad4a229cf99bb1aa88dc189b7db5815ea7200b9b7fdc54de2a6a1f4c8c3a5220862
7
- data.tar.gz: b5b6479f618f27ff27844371f0fc43b62ad29eaac164cc5f72d5efa47c59d02101dff8d1dbc278110174aba25aa63906e38fdd6b7c8616761c881e37db3bc72f
6
+ metadata.gz: d3db4deea8e6f421c1189d328298f1acf38f2058f33fff6d11b3413c898a674159130252e5131992268871e4a217de19b051e516c76ddc128d27688865a92403
7
+ data.tar.gz: 2cdd2d036d9d1abb8680abe9b97a904a6608f650093579897f7b00dc3b3dd874971eae85ede66d308371a0d46c1f5362a0f7cb543dc5d997ff092f48c25ba0ca
@@ -5,9 +5,13 @@ class Twenty::Command::Connect < Twenty::Command
5
5
  description: "Connect a project to twenty"
6
6
  set_option "-p PATH", "--path PATH", "The path to a project", default: nil
7
7
 
8
- prepend Twenty::Command::MigrationMixin
9
- prepend Twenty::Command::SQLiteMixin
10
- prepend Twenty::Command::RescueMixin
8
+ ##
9
+ # Hooks
10
+ # Run order:
11
+ # Rescue -> SQLiteConn -> RequireMigration -> command
12
+ prepend Hook::RequireMigration
13
+ prepend Hook::SQLiteConn
14
+ prepend Hook::Rescue
11
15
 
12
16
  def run
13
17
  options = parse_options(argv)
@@ -17,6 +21,7 @@ class Twenty::Command::Connect < Twenty::Command
17
21
  private
18
22
 
19
23
  def run_command(options)
24
+ require "twenty/server/model"
20
25
  path = File.realpath(options.path ? options.path : Dir.getwd)
21
26
  if File.exist?(path)
22
27
  project = Twenty::Project.create(
@@ -3,10 +3,18 @@
3
3
  class Twenty::Command::Console < Twenty::Command
4
4
  set_banner usage: "twenty console [OPTIONS]",
5
5
  description: "Start the twenty developer console"
6
- include CommonOptionMixin
7
- prepend Twenty::Command::MigrationMixin
8
- prepend Twenty::Command::SQLiteMixin
9
- prepend Twenty::Command::RescueMixin
6
+
7
+ ##
8
+ # Option(s)
9
+ include Option::Database
10
+
11
+ ##
12
+ # Hooks
13
+ # Run order:
14
+ # Rescue -> SQLiteConn -> RequireMigration -> command
15
+ prepend Hook::RequireMigration
16
+ prepend Hook::SQLiteConn
17
+ prepend Hook::Rescue
10
18
 
11
19
  def run
12
20
  options = parse_options(argv)
@@ -16,6 +24,7 @@ class Twenty::Command::Console < Twenty::Command
16
24
  private
17
25
 
18
26
  def run_command(options)
27
+ require "twenty/server/model"
19
28
  require "irb"
20
29
  TOPLEVEL_BINDING.irb
21
30
  end
@@ -4,9 +4,12 @@ class Twenty::Command::Disconnect < Twenty::Command
4
4
  set_banner usage: "twenty disconnect [OPTIONS]",
5
5
  description: "Disconnect a project from twenty"
6
6
  set_option "-p PATH", "--path PATH", "The path to a project", default: nil
7
- prepend Twenty::Command::MigrationMixin
8
- prepend Twenty::Command::SQLiteMixin
9
- prepend Twenty::Command::RescueMixin
7
+
8
+ ##
9
+ # Hooks
10
+ prepend Hook::RequireMigration
11
+ prepend Hook::SQLiteConn
12
+ prepend Hook::Rescue
10
13
 
11
14
  def run
12
15
  options = parse_options(argv)
@@ -16,6 +19,7 @@ class Twenty::Command::Disconnect < Twenty::Command
16
19
  private
17
20
 
18
21
  def run_command(options)
22
+ require "twenty/server/model"
19
23
  path = File.realpath(options.path ? options.path : Dir.getwd)
20
24
  Twenty::Project
21
25
  .where(path:)
@@ -3,9 +3,13 @@
3
3
  class Twenty::Command::Down < Twenty::Command
4
4
  set_banner usage: "twenty down [OPTIONS]",
5
5
  description: "Stop the twenty web server"
6
- include Twenty::Path
7
- prepend Twenty::Command::SQLiteMixin
8
- prepend Twenty::Command::RescueMixin
6
+
7
+ ##
8
+ # Hooks
9
+ # Run order:
10
+ # Rescue -> SQLiteConn -> command
11
+ prepend Hook::SQLiteConn
12
+ prepend Hook::Rescue
9
13
 
10
14
  def run
11
15
  options = parse_options(argv)
@@ -15,19 +19,18 @@ class Twenty::Command::Down < Twenty::Command
15
19
  private
16
20
 
17
21
  def run_command(options)
18
- if File.readable?(pidfile)
19
- Process.kill("SIGINT", Integer(pid))
22
+ if File.readable?(pid)
23
+ pid = Integer(File.binread(pid).gsub(/[^\d]/, ""))
24
+ Process.kill("SIGINT", pid)
20
25
  else
21
- warn "PID file is not readable."
26
+ warn "[x] #{pid} is not readable"
22
27
  end
23
28
  rescue Errno::ESRCH
24
- warn "No such process."
25
- FileUtils.rm(pidfile)
29
+ warn "[x] Process not found"
30
+ rm(pid)
26
31
  end
27
32
 
28
33
  def pid
29
- @pid ||= File
30
- .binread(pidfile)
31
- .gsub(/[^\d]/, "")
34
+ Twenty.pid
32
35
  end
33
36
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twenty::Command::Hook
4
+ module RequireMigration
5
+ def run_command(...)
6
+ if pending_migrations?
7
+ warn "There are pending migrations.\n" \
8
+ "Run \"twenty migrate\" first.\n"
9
+ exit(1)
10
+ else
11
+ super(...)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def pending_migrations?
18
+ Twenty::Migration.pending_migrations?
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Twenty::Command
4
- module RescueMixin
3
+ module Twenty::Command::Hook
4
+ module Rescue
5
+ FRAME_MAX = 15
6
+
5
7
  def run(...)
6
8
  super(...)
7
9
  rescue => ex
@@ -18,7 +20,7 @@ class Twenty::Command
18
20
  private
19
21
 
20
22
  def format_backtrace(backtrace)
21
- backtrace.last(5).map do
23
+ backtrace.last(FRAME_MAX).map do
22
24
  " #{_1.gsub(Dir.getwd, "")}"
23
25
  end.join("\n")
24
26
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twenty::Command::Hook
4
+ module SQLiteConn
5
+ def run_command(options)
6
+ path = options.database || Twenty.default_database
7
+ Twenty.establish_connection(path:)
8
+ super(options)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Twenty::Command::Hook
2
+ require_relative "hook/require_migration"
3
+ require_relative "hook/sqlite_conn"
4
+ require_relative "hook/rescue"
5
+ end
@@ -3,9 +3,18 @@
3
3
  class Twenty::Command::Migrate < Twenty::Command
4
4
  set_banner usage: "twenty migrate [OPTIONS]",
5
5
  description: "Migrate the database"
6
- include CommonOptionMixin
7
- prepend Twenty::Command::SQLiteMixin
8
- prepend Twenty::Command::RescueMixin
6
+ set_option "-t TARGET", "--target TARGET", "The target version", default: nil
7
+
8
+ ##
9
+ # Options
10
+ include Option::Database
11
+
12
+ ##
13
+ # Hooks
14
+ # Run order:
15
+ # Rescue -> SQLiteConn -> command.
16
+ prepend Hook::SQLiteConn
17
+ prepend Hook::Rescue
9
18
 
10
19
  def run
11
20
  options = parse_options(argv)
@@ -15,6 +24,6 @@ class Twenty::Command::Migrate < Twenty::Command
15
24
  private
16
25
 
17
26
  def run_command(options)
18
- Twenty::Migration.run!
27
+ Twenty::Migration.run!(target: options.target)
19
28
  end
20
29
  end
@@ -6,7 +6,7 @@ class Twenty::Command
6
6
  mod.module_eval do
7
7
  set_option "-d PATH",
8
8
  "--database PATH",
9
- "The path to an alternate SQLite3 database",
9
+ "The path to an alternate SQLite database",
10
10
  as: String,
11
11
  default: nil
12
12
  end
@@ -0,0 +1,13 @@
1
+ module Twenty::Command::Option
2
+ module Database
3
+ def self.included(mod)
4
+ mod.module_eval do
5
+ set_option "-d PATH",
6
+ "--database PATH",
7
+ "The path to an alternate SQLite database",
8
+ as: String,
9
+ default: nil
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Twenty::Command::Option
2
+ require_relative "option/database"
3
+ end
@@ -16,11 +16,17 @@ class Twenty::Command::Up < Twenty::Command
16
16
  "--unix PATH",
17
17
  "Listen on a UNIX socket"
18
18
 
19
- include CommonOptionMixin
20
- include Twenty::Path
21
- prepend Twenty::Command::MigrationMixin
22
- prepend Twenty::Command::SQLiteMixin
23
- prepend Twenty::Command::RescueMixin
19
+ ##
20
+ # Option(s)
21
+ include Option::Database
22
+
23
+ ##
24
+ # Hooks
25
+ # Run order:
26
+ # Rescue -> SQLiteConn -> RequireMigration -> command
27
+ prepend Hook::RequireMigration
28
+ prepend Hook::SQLiteConn
29
+ prepend Hook::Rescue
24
30
 
25
31
  def run
26
32
  options = parse_options(argv)
@@ -30,12 +36,17 @@ class Twenty::Command::Up < Twenty::Command
30
36
  private
31
37
 
32
38
  def run_command(options)
33
- File.binwrite(pidfile, Process.pid.to_s)
39
+ require "twenty/server/model"
40
+ File.binwrite(pid, Process.pid.to_s)
34
41
  thr = Twenty::Rack.server(options).start
35
42
  thr.join
36
43
  rescue Interrupt
37
44
  thr.kill
38
45
  ensure
39
- FileUtils.rm(pidfile)
46
+ FileUtils.rm(pid)
47
+ end
48
+
49
+ def pid
50
+ Twenty.pid
40
51
  end
41
52
  end
@@ -4,14 +4,12 @@ require "cmd"
4
4
 
5
5
  class Twenty::Command < Cmd
6
6
  ##
7
- # mixins
8
- require_relative "command/mixin/common_option_mixin"
9
- require_relative "command/mixin/migration_mixin"
10
- require_relative "command/mixin/sqlite_mixin"
11
- require_relative "command/mixin/rescue_mixin"
7
+ # Hooks
8
+ require_relative "command/option"
9
+ require_relative "command/hook"
12
10
 
13
11
  ##
14
- # commands
12
+ # Commands
15
13
  require_relative "command/up"
16
14
  require_relative "command/down"
17
15
  require_relative "command/connect"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twenty-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
@@ -110,11 +110,14 @@ files:
110
110
  - "./lib/twenty/cli/command/console.rb"
111
111
  - "./lib/twenty/cli/command/disconnect.rb"
112
112
  - "./lib/twenty/cli/command/down.rb"
113
+ - "./lib/twenty/cli/command/hook.rb"
114
+ - "./lib/twenty/cli/command/hook/require_migration.rb"
115
+ - "./lib/twenty/cli/command/hook/rescue.rb"
116
+ - "./lib/twenty/cli/command/hook/sqlite_conn.rb"
113
117
  - "./lib/twenty/cli/command/migrate.rb"
114
118
  - "./lib/twenty/cli/command/mixin/common_option_mixin.rb"
115
- - "./lib/twenty/cli/command/mixin/migration_mixin.rb"
116
- - "./lib/twenty/cli/command/mixin/rescue_mixin.rb"
117
- - "./lib/twenty/cli/command/mixin/sqlite_mixin.rb"
119
+ - "./lib/twenty/cli/command/option.rb"
120
+ - "./lib/twenty/cli/command/option/database.rb"
118
121
  - "./lib/twenty/cli/command/up.rb"
119
122
  - "./lib/twenty/cli/libexec.rb"
120
123
  - "./libexec/twenty/connect"
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Twenty::Command::MigrationMixin
4
- def run_command(...)
5
- if pending_migrations?
6
- warn "There are pending migrations.\n" \
7
- "Run \"twenty migrate\" first.\n"
8
- exit(1)
9
- else
10
- super(...)
11
- end
12
- end
13
-
14
- private
15
-
16
- def pending_migrations?
17
- Twenty::Migration.pending_migrations?
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Twenty::Command::SQLiteMixin
4
- def run_command(options)
5
- path = options.database || Twenty.default_database
6
- Twenty.establish_connection(path:)
7
- require "twenty/server/migration"
8
- require "twenty/server/model"
9
- super(options)
10
- end
11
- end