twenty-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e329d8e32ffab71034b7d841e2c79e28931efa0ab0c2693b3cff3ec8053f9694
4
+ data.tar.gz: 0f10118952d860eff2d883ab19d96b726d643bfb7ae681a65911f1c30b744016
5
+ SHA512:
6
+ metadata.gz: 1d7160399c9a90ddd1056545a307b6a825d358d3ef4d386bbe70c1c3496903b29da457270472d808a8490550a8310f98bd819aeab0fa0a8c810195ee5e0634e6
7
+ data.tar.gz: 3391ee8ca66a754cfe66aaa7a596397de3074ca05e439d47b5876423958e76b6dce3bce1ba15a52922d5f79ef3f2d68503cde2c6e34bdf58a0f29ecc22ad5859
data/bin/twenty ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ libdir = File.join(__dir__, "..", "lib")
5
+ require File.join(libdir, "twenty-cli", "libexec")
6
+
7
+ case ARGV[0]
8
+ when "up"
9
+ wait spawn("up", *ARGV[1..])
10
+ exit $?.exitstatus
11
+ when "down"
12
+ wait spawn("down", *ARGV[1..])
13
+ exit $?.exitstatus
14
+ when "connect"
15
+ wait spawn("connect", *ARGV[1..])
16
+ exit $?.exitstatus
17
+ when "disconnect"
18
+ wait spawn("disconnect", *ARGV[1..])
19
+ exit $?.exitstatus
20
+ when "migrate"
21
+ wait spawn("migrate", *ARGV[1..])
22
+ exit $?.exitstatus
23
+ when "console"
24
+ wait spawn("console", *ARGV[1..])
25
+ exit $?.exitstatus
26
+ else
27
+ warn "Usage: twenty COMMAND [OPTIONS]\n\n" \
28
+ "Commands:\n" \
29
+ " up Start the twenty web server.\n" \
30
+ " down Stop the twenty web server.\n" \
31
+ " connect Connect a project to twenty.\n" \
32
+ " disconnect Disconnect a project from twenty.\n" \
33
+ " migrate Migrate the database.\n" \
34
+ " console Start the twenty developer console.\n" \
35
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Twenty::Command::Connect < Twenty::Command
4
+ set_banner usage: "twenty connect [OPTIONS]",
5
+ description: "Connect a project to twenty"
6
+ prepend Twenty::Command::MigrationMixin
7
+ prepend Twenty::Command::SQLiteMixin
8
+
9
+ def run
10
+ options = parse_options(argv)
11
+ options.help ? show_help : run_command(options)
12
+ end
13
+
14
+ private
15
+
16
+ def run_command(options)
17
+ Twenty::Project.new(
18
+ name: File.basename(Dir.getwd),
19
+ path: Dir.getwd
20
+ ).save!
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Twenty::Command::Console < Twenty::Command
4
+ set_banner usage: "twenty console [OPTIONS]",
5
+ description: "Start the twenty developer console"
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
+ require "irb"
19
+ TOPLEVEL_BINDING.irb
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Twenty::Command::Disconnect < Twenty::Command
4
+ set_banner usage: "twenty disconnect [OPTIONS]",
5
+ description: "Disconnect a project from twenty"
6
+ prepend Twenty::Command::MigrationMixin
7
+ prepend Twenty::Command::SQLiteMixin
8
+
9
+ def run
10
+ options = parse_options(argv)
11
+ options.help ? show_help : run_command(options)
12
+ end
13
+
14
+ private
15
+
16
+ def run_command(options)
17
+ warn "[twenty] disconnect..."
18
+ end
19
+ end
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Twenty::Command::Migrate < Twenty::Command
4
+ set_banner usage: "twenty migrate [OPTIONS]",
5
+ description: "Migrate the database"
6
+ include CommonOptionMixin
7
+ prepend Twenty::Command::SQLiteMixin
8
+
9
+ def run
10
+ options = parse_options(argv)
11
+ options.help ? show_help : run_command(options)
12
+ end
13
+
14
+ private
15
+
16
+ def run_command(options)
17
+ Twenty::Migration.run!
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ class Twenty::Command
2
+ module CommonOptionMixin
3
+ def self.included(mod)
4
+ mod.module_eval do
5
+ set_option "-d PATH",
6
+ "--database PATH",
7
+ "The path to an alternate SQLite3 database",
8
+ as: String,
9
+ default: nil
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,7 @@
1
+ module Twenty::Command::SQLiteMixin
2
+ def run_command(options)
3
+ path = options.database || Twenty.default_database
4
+ Twenty.establish_connection(path:)
5
+ super(options)
6
+ end
7
+ end
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cmd"
4
+
5
+ class Twenty::Command < Cmd
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
+
12
+ ##
13
+ # commands
14
+ require_relative "command/up"
15
+ require_relative "command/down"
16
+ require_relative "command/connect"
17
+ require_relative "command/disconnect"
18
+ require_relative "command/migrate"
19
+ require_relative "command/console"
20
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ def spawn(exec, *)
4
+ libexec_dir = File.realpath(File.join(__dir__, "..", "..", "libexec", "twenty"))
5
+ Process.spawn(File.join(libexec_dir, exec), *)
6
+ end
7
+
8
+ def wait(pid)
9
+ Process.wait(pid)
10
+ rescue Interrupt
11
+ retry
12
+ end
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-backend"
6
+ require "twenty-frontend"
7
+ require_relative "twenty-cli/command"
8
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twenty-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - '0x1eef'
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cmd.rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.5.7
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.5.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.1'
97
+ description: 'twenty: command-line interface'
98
+ email:
99
+ - 0x1eef@protonmail.com
100
+ executables:
101
+ - twenty
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
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"
118
+ - bin/twenty
119
+ homepage: https://github.com/0x1eef/twenty#readme
120
+ licenses:
121
+ - 0BSD
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.4.19
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: 'twenty: command-line interface'
142
+ test_files: []