twenty-cli 0.3.5 → 0.4.0

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: 02ffbcbc1469c436068a744196bb3b2d21b5f75666565b510ef72fc112bdcfe2
4
- data.tar.gz: a9a08aa7257d2b60873da4c5aed54393a1150f6d1f23a6532f0ce22ad24b268c
3
+ metadata.gz: 2d9a6a045f05746636ba95a807ef653ad26f003c36981f6f3830d95818d4781a
4
+ data.tar.gz: 55db9d8d8d9c1e63abf36d52e1ab018133fc6778b40145cb8f1b98c3667feb80
5
5
  SHA512:
6
- metadata.gz: 6f38a296f2855760d07a71fa1f17409db6d36fbf6762a2dfec101fe009f98a71bdf356320db955e63ef215da5b5829652049c52c56ad62a80f96bc3e32713334
7
- data.tar.gz: 94ced3c64a02e1bc2c8a7ce2d1e6b30e72f4f3a601a7a68ea368f68e7fe173a7c5d9ba1ecf44d530794bf74b14a6e3739dd3f79ae04138ce4ad59a32440db77b
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"
@@ -24,7 +24,7 @@ when "console"
24
24
  wait spawn("console", *ARGV[1..])
25
25
  exit $?.exitstatus
26
26
  else
27
- warn "Usage: 20 COMMAND [OPTIONS]\n\n" \
27
+ warn "Usage: twenty COMMAND [OPTIONS]\n\n" \
28
28
  "Commands:\n" \
29
29
  " up Start the twenty web server.\n" \
30
30
  " down Stop the twenty web server.\n" \
@@ -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.5
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-16 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,14 +16,28 @@ 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
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: test-unit
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,44 +86,42 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.13'
89
+ version: '1.35'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '1.13'
83
- description: 'twenty: command-line interface'
96
+ version: '1.35'
97
+ description: Command-line interface
84
98
  email:
85
99
  - 0x1eef@protonmail.com
86
100
  executables:
87
101
  - twenty
88
- - '20'
89
102
  extensions: []
90
103
  extra_rdoc_files: []
91
104
  files:
92
- - "./bin/20"
93
105
  - "./bin/twenty"
94
- - "./lib/twenty-cli.rb"
95
- - "./lib/twenty-cli/command.rb"
96
- - "./lib/twenty-cli/command/connect.rb"
97
- - "./lib/twenty-cli/command/console.rb"
98
- - "./lib/twenty-cli/command/disconnect.rb"
99
- - "./lib/twenty-cli/command/down.rb"
100
- - "./lib/twenty-cli/command/migrate.rb"
101
- - "./lib/twenty-cli/command/mixin/common_option_mixin.rb"
102
- - "./lib/twenty-cli/command/mixin/migration_mixin.rb"
103
- - "./lib/twenty-cli/command/mixin/sqlite_mixin.rb"
104
- - "./lib/twenty-cli/command/up.rb"
105
- - "./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"
106
119
  - "./libexec/twenty/connect"
107
120
  - "./libexec/twenty/console"
108
121
  - "./libexec/twenty/disconnect"
109
122
  - "./libexec/twenty/down"
110
123
  - "./libexec/twenty/migrate"
111
124
  - "./libexec/twenty/up"
112
- - bin/20
113
125
  - bin/twenty
114
126
  homepage: https://github.com/0x1eef/twenty#readme
115
127
  licenses:
@@ -130,8 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
142
  - !ruby/object:Gem::Version
131
143
  version: '0'
132
144
  requirements: []
133
- rubygems_version: 3.4.19
145
+ rubygems_version: 3.5.9
134
146
  signing_key:
135
147
  specification_version: 4
136
- summary: 'twenty: command-line interface'
148
+ summary: Command-line interface
137
149
  test_files: []
data/bin/20 DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ruby
2
- Process.wait spawn([File.join(__dir__, "twenty"), "20"], *ARGV)
@@ -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