homebrew-core/Formula/litecli.rb

112 lines
4.1 KiB
Ruby

class Litecli < Formula
include Language::Python::Virtualenv
desc "CLI for SQLite Databases with auto-completion and syntax highlighting"
homepage "https://github.com/dbcli/litecli"
url "https://files.pythonhosted.org/packages/c1/92/b2eb5f098446a05b9a92e548bd83442f2169f87f3e1b37ffed7a5315c264/litecli-1.9.0.tar.gz"
sha256 "21af2cfa083dd4df1e3ccaa2a2117129b5f17212756f596ea090e296776c27a1"
license "BSD-3-Clause"
revision 1
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "b97169f3d2ad603fd47711e054a62b9a921ee9439c9835ee21334f8ce965b67f"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "21d2b95e8dc5425f9e2a536e18c31a4bc10571e74db1799b546fcf75558080a2"
sha256 cellar: :any_skip_relocation, monterey: "b781f2b36b03c0a0818ba23e44fcebc0d7298fdc592ef6ab926bfccf27c02a03"
sha256 cellar: :any_skip_relocation, big_sur: "a721921ed7081672e9e4daf0f132fcad3b97cdfc8b789cecf21d1975f48f6a56"
sha256 cellar: :any_skip_relocation, catalina: "2c33653b3321ea402acca08777cd4d65e90912ab02bde50fe75445c17e5e7363"
sha256 cellar: :any_skip_relocation, x86_64_linux: "980d2cd71ab0022fdae1f03d680bc3546c79278d97f8d639cda27bd1cb847022"
end
depends_on "libpython-tabulate"
depends_on "python@3.10"
depends_on "six"
uses_from_macos "sqlite"
resource "cli-helpers" do
url "https://files.pythonhosted.org/packages/d9/5d/bd0b08f7f8f9d02f44055cf4b41aafa658c1b0731237f303b9fdb49fc8d7/cli_helpers-2.2.1.tar.gz"
sha256 "0ccc1cfcda1ac64dc7ed83d7013055cf19e5979d29e56c21f3b692de01555aae"
end
resource "click" do
url "https://files.pythonhosted.org/packages/59/87/84326af34517fca8c58418d148f2403df25303e02736832403587318e9e8/click-8.1.3.tar.gz"
sha256 "7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"
end
resource "configobj" do
url "https://files.pythonhosted.org/packages/64/61/079eb60459c44929e684fa7d9e2fdca403f67d64dd9dbac27296be2e0fab/configobj-5.0.6.tar.gz"
sha256 "a2f5650770e1c87fb335af19a9b7eb73fc05ccf22144eb68db7d00cd2bcb0902"
end
resource "prompt-toolkit" do
url "https://files.pythonhosted.org/packages/59/68/4d80f22e889ea34f20483ae3d4ca3f8d15f15264bcfb75e52b90fb5aefa5/prompt_toolkit-3.0.29.tar.gz"
sha256 "bd640f60e8cecd74f0dc249713d433ace2ddc62b65ee07f96d358e0b152b6ea7"
end
resource "Pygments" do
url "https://files.pythonhosted.org/packages/59/0f/eb10576eb73b5857bc22610cdfc59e424ced4004fe7132c8f2af2cc168d3/Pygments-2.12.0.tar.gz"
sha256 "5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb"
end
resource "sqlparse" do
url "https://files.pythonhosted.org/packages/32/fe/8a8575debfd924c8160295686a7ea661107fc34d831429cce212b6442edb/sqlparse-0.4.2.tar.gz"
sha256 "0c00730c74263a94e5a9919ade150dfc3b19c574389985446148402998287dae"
end
resource "wcwidth" do
url "https://files.pythonhosted.org/packages/89/38/459b727c381504f361832b9e5ace19966de1a235d73cdbdea91c771a1155/wcwidth-0.2.5.tar.gz"
sha256 "c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83"
end
def install
virtualenv_install_with_resources
end
test do
(testpath/".config/litecli/config").write <<~EOS
[main]
table_format = tsv
less_chatty = True
EOS
(testpath/"test.sql").write <<~EOS
CREATE TABLE IF NOT EXISTS package_manager (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(256)
);
INSERT INTO
package_manager (name)
VALUES
('Homebrew');
EOS
system "sqlite3 test.db < test.sql"
require "pty"
output = ""
PTY.spawn("#{bin}/litecli test.db") do |r, w, _pid|
sleep 2
w.puts "SELECT name FROM package_manager"
w.puts "quit"
begin
r.each_line { |line| output += line }
rescue Errno::EIO
# GNU/Linux raises EIO when read is done on closed pty
end
end
# remove ANSI colors
output.gsub!(/\e\[([;\d]+)?m/, "")
# normalize line endings
output.gsub!(/\r\n/, "\n")
expected = <<~EOS
name
Homebrew
1 row in set
EOS
assert_match expected, output
end
end