twenty-cli 0.5.4 → 0.5.6
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 +4 -4
- data/lib/twenty/cli/command/connect.rb +8 -3
- data/lib/twenty/cli/command/console.rb +13 -4
- data/lib/twenty/cli/command/disconnect.rb +7 -3
- data/lib/twenty/cli/command/down.rb +14 -11
- data/lib/twenty/cli/command/hook/require_migration.rb +22 -0
- data/lib/twenty/cli/command/{mixin/rescue_mixin.rb → hook/rescue.rb} +9 -5
- data/lib/twenty/cli/command/hook/sqlite_conn.rb +11 -0
- data/lib/twenty/cli/command/hook.rb +5 -0
- data/lib/twenty/cli/command/migrate.rb +13 -4
- data/lib/twenty/cli/command/mixin/common_option_mixin.rb +1 -1
- data/lib/twenty/cli/command/option/database.rb +13 -0
- data/lib/twenty/cli/command/option.rb +3 -0
- data/lib/twenty/cli/command/up.rb +18 -7
- data/lib/twenty/cli/command.rb +4 -6
- metadata +7 -4
- data/lib/twenty/cli/command/mixin/migration_mixin.rb +0 -19
- data/lib/twenty/cli/command/mixin/sqlite_mixin.rb +0 -11
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 11aeb74ec54a850fe0d39de13bb11c4da47e452e4e27adb7eb43dc69f6c7237c
         | 
| 4 | 
            +
              data.tar.gz: 7ae6e0a4e454e395cd4eb4a60e7fb446099cc19c8bcda15e11d7533e21abbaec
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
               | 
| 9 | 
            -
               | 
| 10 | 
            -
               | 
| 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 | 
            -
             | 
| 7 | 
            -
               | 
| 8 | 
            -
               | 
| 9 | 
            -
               | 
| 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 | 
            -
             | 
| 8 | 
            -
               | 
| 9 | 
            -
               | 
| 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 | 
            -
             | 
| 7 | 
            -
               | 
| 8 | 
            -
               | 
| 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?( | 
| 19 | 
            -
                   | 
| 22 | 
            +
                if File.readable?(pid)
         | 
| 23 | 
            +
                  pid = Integer(File.binread(pid).gsub(/[^\d]/, ""))
         | 
| 24 | 
            +
                  Process.kill("SIGINT", pid)
         | 
| 20 25 | 
             
                else
         | 
| 21 | 
            -
                  warn " | 
| 26 | 
            +
                  warn "[x] #{pid} is not readable"
         | 
| 22 27 | 
             
                end
         | 
| 23 28 | 
             
              rescue Errno::ESRCH
         | 
| 24 | 
            -
                warn " | 
| 25 | 
            -
                 | 
| 29 | 
            +
                warn "[x] Process not found"
         | 
| 30 | 
            +
                rm(pid)
         | 
| 26 31 | 
             
              end
         | 
| 27 32 |  | 
| 28 33 | 
             
              def pid
         | 
| 29 | 
            -
                 | 
| 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 | 
            -
             | 
| 4 | 
            -
              module  | 
| 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 | 
            -
                                 | 
| 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. | 
| 22 | 
            -
                    " | 
| 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
         | 
| @@ -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 | 
            -
               | 
| 7 | 
            -
             | 
| 8 | 
            -
               | 
| 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
         | 
| @@ -16,11 +16,17 @@ class Twenty::Command::Up < Twenty::Command | |
| 16 16 | 
             
                         "--unix PATH",
         | 
| 17 17 | 
             
                         "Listen on a UNIX socket"
         | 
| 18 18 |  | 
| 19 | 
            -
               | 
| 20 | 
            -
               | 
| 21 | 
            -
               | 
| 22 | 
            -
             | 
| 23 | 
            -
               | 
| 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 | 
            -
                 | 
| 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( | 
| 46 | 
            +
                FileUtils.rm(pid)
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              def pid
         | 
| 50 | 
            +
                Twenty.pid
         | 
| 40 51 | 
             
              end
         | 
| 41 52 | 
             
            end
         | 
    
        data/lib/twenty/cli/command.rb
    CHANGED
    
    | @@ -4,14 +4,12 @@ require "cmd" | |
| 4 4 |  | 
| 5 5 | 
             
            class Twenty::Command < Cmd
         | 
| 6 6 | 
             
              ##
         | 
| 7 | 
            -
              #  | 
| 8 | 
            -
              require_relative "command/ | 
| 9 | 
            -
              require_relative "command/ | 
| 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 | 
            -
              #  | 
| 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 | 
            +
              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/ | 
| 116 | 
            -
            - "./lib/twenty/cli/command/ | 
| 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
         |