Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,17 @@ jobs:
- uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
with:
toolchain: "1.98"
- name: Build and install both executables
- name: Build and install both executables and the completions
run: |
cd "source tree/linux"
meson setup "build dir" -Dprofile=development
meson compile -C "build dir"
DESTDIR="$PWD/install root" meson install -C "build dir" --no-rebuild
test -x "install root/usr/local/bin/tablepro"
test -x "install root/usr/local/libexec/tablepro-askpass"
test -s "install root/usr/local/share/bash-completion/completions/tablepro"
test -s "install root/usr/local/share/zsh/site-functions/_tablepro"
test -s "install root/usr/local/share/fish/vendor_completions.d/tablepro.fish"

supply-chain:
name: Supply chain
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
run: |
cargo check --locked --target "$TARGET" --features "$FEATURES" --features "$IN_PROCESS_SSH" \
-p tablepro-core -p tablepro-net -p tablepro-storage -p tablepro-ssh -p tablepro-session \
-p tablepro-foreign-import -p tablepro-ai -p tablepro-mcp -p tablepro-account \
-p tablepro-foreign-import -p tablepro-ai -p tablepro-mcp -p tablepro-account -p tablepro-cli \
-p tablepro-test-support -p tablepro-test-fixtures \
-p tablepro-driver-cassandra -p tablepro-driver-clickhouse -p tablepro-driver-duckdb \
-p tablepro-driver-mongodb -p tablepro-driver-mssql -p tablepro-driver-mysql \
Expand Down
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"core/crates/account",
"core/crates/ai",
"core/crates/bindgen",
"core/crates/cli",
"core/crates/core",
"core/crates/ffi",
"core/crates/foreign-import",
Expand Down Expand Up @@ -36,6 +37,7 @@ publish = false
[workspace.dependencies]
tablepro-account = { path = "core/crates/account" }
tablepro-ai = { path = "core/crates/ai" }
tablepro-cli = { path = "core/crates/cli" }
tablepro-core = { path = "core/crates/core" }
tablepro-driver-cassandra = { path = "core/crates/drivers/cassandra" }
tablepro-driver-clickhouse = { path = "core/crates/drivers/clickhouse" }
Expand Down
2 changes: 2 additions & 0 deletions apple/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ custom_rules:
- '.*/[^/]*Tests/'
- '.*Tests\.swift$'
- '.*/(WebPageOpener|DataLinkPolicy|MCPPairingService|NotificationsSettingsView|SyncSettingsView|ConnectionRecoveryPerformer|OpenConnectionIntent)\.swift$'
# Open TablePro's own links, and the user's files and URLs, in the TablePro bundle the command ships in.
- '.*/(Handshake|CLILiveEnvironment)\.swift$'
- '.*/(AppDelegate\+MainMenuActions|WhatsNewWindowController|SupportAskCoordinator|MainContentCoordinator\+Rewind|GoogleSignInService|ChatGPTCodexService)\.swift$'
excluded_match_kinds: [comment, doccomment]
message: "Open a URL from a server, a plugin or a file through WebPageOpener. NSWorkspace opens a file: path, an smb: share or any app's scheme as readily as a web page."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(AppKit)
import AppKit
#endif

public enum ProcessLaunchError: Error, Equatable, Sendable, LocalizedError {
case executableNotAbsolute(String)
Expand Down Expand Up @@ -36,6 +39,18 @@ private extension String {
#endif

public enum ProcessLauncher {
#if canImport(AppKit)
public static func openConfiguration(
environment: [String: String],
activates: Bool = true
) -> NSWorkspace.OpenConfiguration {
let configuration = NSWorkspace.OpenConfiguration()
configuration.environment = environment
configuration.activates = activates
return configuration
}
#endif

static let shellNames: Set<String> = ["sh", "bash", "zsh", "dash", "ksh", "csh", "tcsh", "fish", "env"]

// The only place production code makes a `Process`. It comes back configured and not yet running,
Expand Down
28 changes: 27 additions & 1 deletion apple/Packages/TableProMacCore/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let package = Package(
.library(name: "TableProUtilities", targets: ["TableProUtilities"]),
.library(name: "TableProSSHConfig", targets: ["TableProSSHConfig"]),
.library(name: "TableProMCP", targets: ["TableProMCP"]),
// Only the tablepro-cli tool links this; the app never does, so ArgumentParser stays out of it.
.library(name: "TableProCommandLine", targets: ["TableProCommandLine"]),
.library(name: "TableProMCPTestSupport", targets: ["TableProMCPTestSupport"]),
.library(name: "TableProCloudAPI", targets: ["TableProCloudAPI"])
],
Expand All @@ -28,7 +30,9 @@ let package = Package(
// Exact: the versions clients.md (macOS, Dependencies) names.
.package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.14.1"),
.package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.13.0"),
.package(url: "https://github.com/apple/swift-openapi-urlsession", exact: "1.4.0")
.package(url: "https://github.com/apple/swift-openapi-urlsession", exact: "1.4.0"),
// Exact: the pin swift-openapi-generator already resolves, and licenses.yml names this version.
.package(url: "https://github.com/apple/swift-argument-parser", exact: "1.8.2")
],
targets: [
.target(
Expand Down Expand Up @@ -63,6 +67,18 @@ let package = Package(
path: "Sources/TableProMCP",
swiftSettings: appModuleSettings
),
.target(
name: "TableProCommandLine",
dependencies: [
"TableProMCP",
"TableProUtilities",
.product(name: "TableProCoreTypes", package: "TableProCore"),
.product(name: "TableProProcess", package: "TableProCore"),
.product(name: "ArgumentParser", package: "swift-argument-parser")
],
path: "Sources/TableProCommandLine",
swiftSettings: appModuleSettings
),
// openapi.json is a copy of tablepro-cloud's api/v2.json; scripts/update-cloud-api.sh refreshes it.
.target(
name: "TableProCloudAPI",
Expand Down Expand Up @@ -111,6 +127,16 @@ let package = Package(
],
path: "Tests/TableProMCPTests",
swiftSettings: appModuleSettings
),
.testTarget(
name: "TableProCommandLineTests",
dependencies: [
"TableProCommandLine",
"TableProMCP",
"TableProMCPTestSupport"
],
path: "Tests/TableProCommandLineTests",
swiftSettings: appModuleSettings
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import ArgumentParser
import Foundation
import TableProMCP

struct ConnectionsCommand: ParsableCommand, CLIRunnable {
static let configuration = CommandConfiguration(
commandName: "connections",
abstract: "List the saved connections this command can use."
)

@OptionGroup var output: FormatOption

func run(in session: CLISession) async throws {
let client = try await session.connect()
let listing = try await session.call(client, "list_connections", [:])
let rows = (listing["connections"]?.arrayValue ?? []).map { entry in
[entry["name"] ?? .null, entry["id"] ?? .null, entry["type"] ?? .null]
}
session.write([CLIResultSet(columns: ["name", "id", "type"], rows: rows)], format: output.format ?? session.defaultFormat)
}
}

struct DatabasesCommand: ParsableCommand, CLIRunnable {
static let configuration = CommandConfiguration(
commandName: "databases",
abstract: "List a connection's databases."
)

@OptionGroup var connection: ConnectionOption
@OptionGroup var output: FormatOption

func run(in session: CLISession) async throws {
let client = try await session.connect()
let connectionId = try await session.resolveConnection(connection.connection, client: client)
let listing = try await session.call(client, "list_databases", ["connection_id": .string(connectionId)])
let rows = (listing["databases"]?.arrayValue ?? []).map { [$0] }
session.write([CLIResultSet(columns: ["name"], rows: rows)], format: output.format ?? session.defaultFormat)
}
}

struct SchemasCommand: ParsableCommand, CLIRunnable {
static let configuration = CommandConfiguration(
commandName: "schemas",
abstract: "List a connection's schemas."
)

@OptionGroup var connection: ConnectionOption
@OptionGroup var database: DatabaseOption
@OptionGroup var output: FormatOption

func run(in session: CLISession) async throws {
let client = try await session.connect()
let connectionId = try await session.resolveConnection(connection.connection, client: client)
var arguments: [String: JsonValue] = ["connection_id": .string(connectionId)]
if let name = database.database { arguments["database"] = .string(name) }
let listing = try await session.call(client, "list_schemas", arguments)
let rows = (listing["schemas"]?.arrayValue ?? []).map { [$0] }
session.write([CLIResultSet(columns: ["name"], rows: rows)], format: output.format ?? session.defaultFormat)
}
}

struct TablesCommand: ParsableCommand, CLIRunnable {
static let configuration = CommandConfiguration(
commandName: "tables",
abstract: "List the tables and views in a schema."
)

@OptionGroup var connection: ConnectionOption
@OptionGroup var database: DatabaseOption
@OptionGroup var schema: SchemaOption
@OptionGroup var output: FormatOption

func run(in session: CLISession) async throws {
let client = try await session.connect()
let connectionId = try await session.resolveConnection(connection.connection, client: client)
var arguments: [String: JsonValue] = ["connection_id": .string(connectionId)]
if let name = database.database { arguments["database"] = .string(name) }
if let name = schema.schema { arguments["schema"] = .string(name) }
let listing = try await session.call(client, "list_tables", arguments)
let rows = (listing["tables"]?.arrayValue ?? []).map { entry in
[entry["schema"] ?? .null, entry["name"] ?? .null, entry["type"] ?? .null]
}
session.write([CLIResultSet(columns: ["schema", "name", "type"], rows: rows)], format: output.format ?? session.defaultFormat)
}
}

struct DescribeCommand: ParsableCommand, CLIRunnable {
static let configuration = CommandConfiguration(
commandName: "describe",
abstract: "Show a table's columns, indexes and foreign keys.",
discussion: "Indexes and foreign keys follow the columns as separate result sets when the table has any."
)

@OptionGroup var connection: ConnectionOption
@OptionGroup var database: DatabaseOption
@OptionGroup var schema: SchemaOption

@Flag(help: "Print the CREATE statement instead.")
var ddl = false

@OptionGroup var output: FormatOption

@Argument(help: ArgumentHelp("The table to describe.", valueName: "table"))
var table: String

func validate() throws {
if ddl, output.format != nil {
throw ValidationError("--ddl prints the statement as text, so it takes no --format.")
}
}

func run(in session: CLISession) async throws {
let client = try await session.connect()
let connectionId = try await session.resolveConnection(connection.connection, client: client)
var arguments: [String: JsonValue] = [
"connection_id": .string(connectionId),
"table": .string(table)
]
if let name = database.database { arguments["database"] = .string(name) }
if let name = schema.schema { arguments["schema"] = .string(name) }
let description = try await session.call(client, "describe_table", arguments)

if ddl {
guard let statement = description["ddl"]?.stringValue, !statement.isEmpty else {
throw CLIFailure(.failure, "TablePro could not produce a CREATE statement for \(table) on this engine.")
}
session.writeText(statement)
return
}
session.write(Self.resultSets(description), format: output.format ?? session.defaultFormat)
}

static func resultSets(_ description: JsonValue) -> [CLIResultSet] {
let columns = (description["columns"]?.arrayValue ?? []).map { column in
[
column["name"] ?? .null,
column["data_type"] ?? .null,
column["is_nullable"] ?? .null,
column["default_value"] ?? .null,
column["is_primary_key"] ?? .null
]
}
var sets = [CLIResultSet(columns: ["name", "type", "nullable", "default", "primary_key"], rows: columns)]

let indexes = (description["indexes"]?.arrayValue ?? []).map { index in
[
index["name"] ?? .null,
joined(index["columns"]),
index["is_unique"] ?? .null,
index["is_primary"] ?? .null
]
}
if !indexes.isEmpty {
sets.append(CLIResultSet(columns: ["index", "columns", "unique", "primary"], rows: indexes))
}

let foreignKeys = (description["foreign_keys"]?.arrayValue ?? []).map { key in
[
key["name"] ?? .null,
key["column"] ?? .null,
key["referenced_table"] ?? .null,
key["referenced_column"] ?? .null,
key["on_delete"] ?? .null,
key["on_update"] ?? .null
]
}
if !foreignKeys.isEmpty {
sets.append(CLIResultSet(
columns: ["foreign_key", "column", "referenced_table", "referenced_column", "on_delete", "on_update"],
rows: foreignKeys
))
}
return sets
}

private static func joined(_ value: JsonValue?) -> JsonValue {
guard let names = value?.arrayValue?.compactMap(\.stringValue) else { return .null }
return .string(names.joined(separator: ", "))
}
}
Loading
Loading