twenty-cli 0.3.4 → 0.4.0

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: 80075d308043ca5acbe578b8f9221829944ce1c2faf4bd1d737a29b22f1309ba
4
- data.tar.gz: 8b78080a733e95579cf49471696af205f31ecd7cebb89bd2d6b530f23c3279d2
3
+ metadata.gz: 2d9a6a045f05746636ba95a807ef653ad26f003c36981f6f3830d95818d4781a
4
+ data.tar.gz: 55db9d8d8d9c1e63abf36d52e1ab018133fc6778b40145cb8f1b98c3667feb80
5
5
  SHA512:
6
- metadata.gz: 14f0acb3e8e9e7bb430e175847c2c3acd8493dc56cfd8a366f60668677f64e38d169a755ea2c3dc61bbedb048b29707841b90d3a3f6a382436044e257b4d40f4
7
- data.tar.gz: dbc2d54b19ae4b1e758093accf3009557faf17941fbbc75f850f6c7fb444448df19aea6a11c0c5b788dfb0bbb19a80d98f5f453365efe76f82375973bb7eb5c0
6
+ metadata.gz: b450d2e1c1074682dbf2fe35f9c2fea183ccdfea42f19bd04b55a8373017e62c8c3553bf17c882d8832a49c5b217b98f4e9f2e7dbce034d533a43ddfd85f916b
7
+ data.tar.gz: d066ed882a336f8415a9ea6657194cb3a79be75da24075c29c099570464b07fb4810204719a8373c1d8ad1593161482d1fb594b5811d123c00ece8319e7a85c6
data/bin/twenty CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  libdir = File.join(__dir__, "..", "lib")
5
- require File.join(libdir, "twenty-cli", "libexec")
5
+ require File.join(libdir, "twenty", "cli", "libexec")
6
6
 
7
7
  case ARGV[0]
8
8
  when "up"
@@ -5,18 +5,19 @@ class Twenty::Command::Connect < Twenty::Command
5
5
  description: "Connect a project to twenty"
6
6
  prepend Twenty::Command::MigrationMixin
7
7
  prepend Twenty::Command::SQLiteMixin
8
+ prepend Twenty::Command::RescueMixin
8
9
 
9
10
  def run
10
11
  options = parse_options(argv)
11
- options.help ? show_help : run_command(options)
12
+ run_command(options)
12
13
  end
13
14
 
14
15
  private
15
16
 
16
17
  def run_command(options)
17
- Twenty::Project.new(
18
+ Twenty::Project.create(
18
19
  name: File.basename(Dir.getwd),
19
20
  path: Dir.getwd
20
- ).save!
21
+ )
21
22
  end
22
23
  end
@@ -6,10 +6,11 @@ class Twenty::Command::Console < Twenty::Command
6
6
  include CommonOptionMixin
7
7
  prepend Twenty::Command::MigrationMixin
8
8
  prepend Twenty::Command::SQLiteMixin
9
+ prepend Twenty::Command::RescueMixin
9
10
 
10
11
  def run
11
12
  options = parse_options(argv)
12
- options.help ? show_help : run_command(options)
13
+ run_command(options)
13
14
  end
14
15
 
15
16
  private
@@ -5,15 +5,19 @@ class Twenty::Command::Disconnect < Twenty::Command
5
5
  description: "Disconnect a project from twenty"
6
6
  prepend Twenty::Command::MigrationMixin
7
7
  prepend Twenty::Command::SQLiteMixin
8
+ prepend Twenty::Command::RescueMixin
8
9
 
9
10
  def run
10
11
  options = parse_options(argv)
11
- options.help ? show_help : run_command(options)
12
+ run_command(options)
12
13
  end
13
14
 
14
15
  private
15
16
 
16
17
  def run_command(options)
17
- warn "[twenty] disconnect..."
18
+ Twenty::Project
19
+ .where(path: Dir.getwd)
20
+ .first!
21
+ .destroy
18
22
  end
19
23
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Twenty::Command::Down < Twenty::Command
4
+ set_banner usage: "twenty down [OPTIONS]",
5
+ description: "Stop the twenty web server"
6
+ include Twenty::Path
7
+ prepend Twenty::Command::SQLiteMixin
8
+ prepend Twenty::Command::RescueMixin
9
+
10
+ def run
11
+ options = parse_options(argv)
12
+ run_command(options)
13
+ end
14
+
15
+ private
16
+
17
+ def run_command(options)
18
+ if File.readable?(pidfile)
19
+ Process.kill("SIGINT", Integer(pid))
20
+ else
21
+ warn "PID file is not readable."
22
+ end
23
+ rescue Errno::ESRCH
24
+ warn "No such process."
25
+ FileUtils.rm(pidfile)
26
+ end
27
+
28
+ def pid
29
+ @pid ||= File
30
+ .binread(pidfile)
31
+ .gsub(/[^\d]/, "")
32
+ end
33
+ end
@@ -5,10 +5,11 @@ class Twenty::Command::Migrate < Twenty::Command
5
5
  description: "Migrate the database"
6
6
  include CommonOptionMixin
7
7
  prepend Twenty::Command::SQLiteMixin
8
+ prepend Twenty::Command::RescueMixin
8
9
 
9
10
  def run
10
11
  options = parse_options(argv)
11
- options.help ? show_help : run_command(options)
12
+ run_command(options)
12
13
  end
13
14
 
14
15
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Twenty::Command
2
4
  module CommonOptionMixin
3
5
  def self.included(mod)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Twenty::Command
4
+ module RescueMixin
5
+ def run(...)
6
+ super(...)
7
+ rescue => ex
8
+ require "paint"
9
+ $stderr.print "\n",
10
+ " ", Paint[" Exception ", :white, :red, :bold], "\n",
11
+ " ", Paint[ex.class.to_s, :bold], "\n",
12
+ " ", ex.message, "\n\n",
13
+ " ", Paint[" Backtrace ", :white, :blue, :bold], "\n",
14
+ format_backtrace(ex.backtrace), "\n",
15
+ "\n"
16
+ end
17
+
18
+ private
19
+
20
+ def format_backtrace(backtrace)
21
+ backtrace.last(5).map do
22
+ " #{_1.gsub(Dir.getwd, "")}"
23
+ end.join("\n")
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Twenty::Command::SQLiteMixin
2
4
  def run_command(options)
3
5
  path = options.database || Twenty.default_database
4
6
  Twenty.establish_connection(path:)
7
+ require "twenty/server/migration"
8
+ require "twenty/server/model"
5
9
  super(options)
6
10
  end
7
11
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Twenty::Command::Up < Twenty::Command
4
+ set_banner usage: "twenty up [OPTIONS]",
5
+ description: "Start the twenty web server"
6
+ set_option "-b ADDR",
7
+ "--bind ADDR",
8
+ "An address to bind to (default: 127.0.0.1)",
9
+ default: "127.0.0.1"
10
+ set_option "-p PORT",
11
+ "--port PORT",
12
+ "A port to listen on (default: 2020)",
13
+ default: 2020,
14
+ as: Integer
15
+ set_option "-u PATH",
16
+ "--unix PATH",
17
+ "Listen on a UNIX socket"
18
+
19
+ include CommonOptionMixin
20
+ include Twenty::Path
21
+ prepend Twenty::Command::MigrationMixin
22
+ prepend Twenty::Command::SQLiteMixin
23
+ prepend Twenty::Command::RescueMixin
24
+
25
+ def run
26
+ options = parse_options(argv)
27
+ run_command(options)
28
+ end
29
+
30
+ private
31
+
32
+ def run_command(options)
33
+ File.binwrite(pidfile, Process.pid.to_s)
34
+ thr = Twenty::Rack.server(options).start
35
+ thr.join
36
+ rescue Interrupt
37
+ thr.kill
38
+ ensure
39
+ FileUtils.rm(pidfile)
40
+ end
41
+ end
@@ -8,6 +8,7 @@ class Twenty::Command < Cmd
8
8
  require_relative "command/mixin/common_option_mixin"
9
9
  require_relative "command/mixin/migration_mixin"
10
10
  require_relative "command/mixin/sqlite_mixin"
11
+ require_relative "command/mixin/rescue_mixin"
11
12
 
12
13
  ##
13
14
  # commands
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  def spawn(exec, *)
4
- libexec_dir = File.realpath(File.join(__dir__, "..", "..", "libexec", "twenty"))
4
+ libexec_dir = File.realpath(File.join(__dir__, "..", "..", "..", "libexec", "twenty"))
5
5
  Process.spawn(File.join(libexec_dir, exec), *)
6
6
  end
7
7
 
data/lib/twenty/cli.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twenty
4
+ require "json"
5
+ require "twenty/server"
6
+ require "twenty/client"
7
+ require_relative "cli/command"
8
+ end
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  libdir = File.expand_path File.join(__dir__, "..", "..", "lib")
5
- require File.join(libdir, "twenty-cli")
5
+ require File.join(libdir, "twenty/cli")
6
6
 
7
7
  ##
8
8
  # main
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  libdir = File.expand_path File.join(__dir__, "..", "..", "lib")
5
- require File.join(libdir, "twenty-cli")
5
+ require File.join(libdir, "twenty/cli")
6
6
 
7
7
  ##
8
8
  # main
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  libdir = File.expand_path File.join(__dir__, "..", "..", "lib")
5
- require File.join(libdir, "twenty-cli")
5
+ require File.join(libdir, "twenty/cli")
6
6
 
7
7
  ##
8
8
  # main
data/libexec/twenty/down CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  libdir = File.expand_path File.join(__dir__, "..", "..", "lib")
5
- require File.join(libdir, "twenty-cli")
5
+ require File.join(libdir, "twenty/cli")
6
6
 
7
7
  ##
8
8
  # main
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  libdir = File.expand_path File.join(__dir__, "..", "..", "lib")
5
- require File.join(libdir, "twenty-cli")
5
+ require File.join(libdir, "twenty/cli")
6
6
 
7
7
  ##
8
8
  # main
data/libexec/twenty/up CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  libdir = File.expand_path File.join(__dir__, "..", "..", "lib")
5
- require File.join(libdir, "twenty-cli")
5
+ require File.join(libdir, "twenty", "cli")
6
6
 
7
7
  ##
8
8
  # main
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twenty-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmd.rb
@@ -16,85 +16,85 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.2'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: test-unit
28
+ name: paint
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.5.7
34
- type: :development
33
+ version: '2.3'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.5.7
40
+ version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: yard
42
+ name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.9'
47
+ version: 3.5.7
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.9'
54
+ version: 3.5.7
55
55
  - !ruby/object:Gem::Dependency
56
- name: redcarpet
56
+ name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.5'
61
+ version: '0.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.5'
68
+ version: '0.9'
69
69
  - !ruby/object:Gem::Dependency
70
- name: standard
70
+ name: redcarpet
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.13'
75
+ version: '3.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.13'
82
+ version: '3.5'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rake
84
+ name: standard
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '13.1'
89
+ version: '1.35'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '13.1'
97
- description: 'twenty: command-line interface'
96
+ version: '1.35'
97
+ description: Command-line interface
98
98
  email:
99
99
  - 0x1eef@protonmail.com
100
100
  executables:
@@ -103,18 +103,19 @@ extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
105
  - "./bin/twenty"
106
- - "./lib/twenty-cli.rb"
107
- - "./lib/twenty-cli/command.rb"
108
- - "./lib/twenty-cli/command/connect.rb"
109
- - "./lib/twenty-cli/command/console.rb"
110
- - "./lib/twenty-cli/command/disconnect.rb"
111
- - "./lib/twenty-cli/command/down.rb"
112
- - "./lib/twenty-cli/command/migrate.rb"
113
- - "./lib/twenty-cli/command/mixin/common_option_mixin.rb"
114
- - "./lib/twenty-cli/command/mixin/migration_mixin.rb"
115
- - "./lib/twenty-cli/command/mixin/sqlite_mixin.rb"
116
- - "./lib/twenty-cli/command/up.rb"
117
- - "./lib/twenty-cli/libexec.rb"
106
+ - "./lib/twenty/cli.rb"
107
+ - "./lib/twenty/cli/command.rb"
108
+ - "./lib/twenty/cli/command/connect.rb"
109
+ - "./lib/twenty/cli/command/console.rb"
110
+ - "./lib/twenty/cli/command/disconnect.rb"
111
+ - "./lib/twenty/cli/command/down.rb"
112
+ - "./lib/twenty/cli/command/migrate.rb"
113
+ - "./lib/twenty/cli/command/mixin/common_option_mixin.rb"
114
+ - "./lib/twenty/cli/command/mixin/migration_mixin.rb"
115
+ - "./lib/twenty/cli/command/mixin/rescue_mixin.rb"
116
+ - "./lib/twenty/cli/command/mixin/sqlite_mixin.rb"
117
+ - "./lib/twenty/cli/command/up.rb"
118
+ - "./lib/twenty/cli/libexec.rb"
118
119
  - "./libexec/twenty/connect"
119
120
  - "./libexec/twenty/console"
120
121
  - "./libexec/twenty/disconnect"
@@ -141,8 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  - !ruby/object:Gem::Version
142
143
  version: '0'
143
144
  requirements: []
144
- rubygems_version: 3.4.19
145
+ rubygems_version: 3.5.9
145
146
  signing_key:
146
147
  specification_version: 4
147
- summary: 'twenty: command-line interface'
148
+ summary: Command-line interface
148
149
  test_files: []
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Twenty::Command::Down < Twenty::Command
4
- set_banner usage: "twenty down [OPTIONS]",
5
- description: "Stop the twenty web server"
6
- prepend Twenty::Command::SQLiteMixin
7
-
8
- def run
9
- options = parse_options(argv)
10
- options.help ? show_help : run_command(options)
11
- end
12
-
13
- private
14
-
15
- def run_command(options)
16
- warn "[twenty] down..."
17
- end
18
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Twenty::Command::Up < Twenty::Command
4
- set_banner usage: "twenty up [OPTIONS]",
5
- description: "Start the twenty web server"
6
- include CommonOptionMixin
7
- prepend Twenty::Command::MigrationMixin
8
- prepend Twenty::Command::SQLiteMixin
9
-
10
- def run
11
- options = parse_options(argv)
12
- options.help ? show_help : run_command(options)
13
- end
14
-
15
- private
16
-
17
- def run_command(options)
18
- server = Twenty::Servlet.server
19
- trap(:SIGINT) { server.shutdown }
20
- server.start
21
- end
22
- end
data/lib/twenty-cli.rb DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Twenty
4
- require "json"
5
- require "twenty-backend"
6
- require "twenty-frontend"
7
- require_relative "twenty-cli/command"
8
- end