twenty-cli 0.5.4 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a07dbee307b110c4d96b36254fafff8432eb57388c74748f84985b5b0f452fc
4
- data.tar.gz: 8badd46d8d4bfe53955082e4e94b87f14f6f9d466ffc7bb3b46e3db835025595
3
+ metadata.gz: 11aeb74ec54a850fe0d39de13bb11c4da47e452e4e27adb7eb43dc69f6c7237c
4
+ data.tar.gz: 7ae6e0a4e454e395cd4eb4a60e7fb446099cc19c8bcda15e11d7533e21abbaec
5
5
  SHA512:
6
- metadata.gz: e9291a9992e134f1fa5872162d053d9be7402810515c020593c89dd2545b1ad4a229cf99bb1aa88dc189b7db5815ea7200b9b7fdc54de2a6a1f4c8c3a5220862
7
- data.tar.gz: b5b6479f618f27ff27844371f0fc43b62ad29eaac164cc5f72d5efa47c59d02101dff8d1dbc278110174aba25aa63906e38fdd6b7c8616761c881e37db3bc72f
6
+ metadata.gz: c30f12237301803e9502f97a1ea1f7fe845f0232acbb77b2a7093007fe5b4e0e5279d088f696b6144402246be56a0c5d43bf7a993a791f50e3cf5e0fcef9ccb0
7
+ data.tar.gz: a23b70eef9714a4ef3a63f30c6c0b39aadd4ba9434fcbe6713196b66734f3dcb2c7ceca9530a88e80dca176cb6caf3ffac831203452b253a6cd32b53358420af
@@ -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,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twenty::Command::Hook
4
+ module RequireMigration
5
+ Error = Class.new(RuntimeError)
6
+
7
+ def run_command(...)
8
+ if pending_migrations?
9
+ raise Error, "There are pending database migrations to run. \n" \
10
+ "Try 'twenty migrate'"
11
+ else
12
+ super(...)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def pending_migrations?
19
+ Twenty::Migration.pending_migrations?
20
+ end
21
+ end
22
+ end
@@ -1,7 +1,10 @@
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
+ INDENT_BY = 2
7
+
5
8
  def run(...)
6
9
  super(...)
7
10
  rescue => ex
@@ -9,7 +12,8 @@ class Twenty::Command
9
12
  $stderr.print "\n",
10
13
  " ", Paint[" Exception ", :white, :red, :bold], "\n",
11
14
  " ", Paint[ex.class.to_s, :bold], "\n",
12
- " ", ex.message, "\n\n",
15
+ ex.message.each_line.map { [" " * INDENT_BY, _1] }.join,
16
+ "\n\n",
13
17
  " ", Paint[" Backtrace ", :white, :blue, :bold], "\n",
14
18
  format_backtrace(ex.backtrace), "\n",
15
19
  "\n"
@@ -18,8 +22,8 @@ class Twenty::Command
18
22
  private
19
23
 
20
24
  def format_backtrace(backtrace)
21
- backtrace.last(5).map do
22
- " #{_1.gsub(Dir.getwd, "")}"
25
+ backtrace[0..FRAME_MAX-1].map do
26
+ [" " * INDENT_BY, _1.gsub(Dir.getwd, "")].join
23
27
  end.join("\n")
24
28
  end
25
29
  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.6
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