WIP: Start on a new cli crate

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-04-15 16:55:26 +02:00
parent 0c98168227
commit 01eb2dce24
5 changed files with 377 additions and 69 deletions

309
Cargo.lock generated
View File

@ -135,7 +135,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -309,7 +309,7 @@ dependencies = [
"polling",
"vec-arena",
"waker-fn",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -364,7 +364,7 @@ dependencies = [
"futures-lite",
"once_cell",
"signal-hook",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -458,7 +458,7 @@ dependencies = [
"async-io",
"async-lock",
"async-process",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
"futures-channel",
"futures-core",
"futures-io",
@ -550,7 +550,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -909,7 +909,7 @@ dependencies = [
"num-traits",
"serde",
"time 0.1.44",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -964,9 +964,9 @@ dependencies = [
[[package]]
name = "clap"
version = "3.0.0-beta.2"
version = "3.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
checksum = "71c47df61d9e16dc010b55dba1952a57d8c215dbb533fd13cdd13369aac73b1c"
dependencies = [
"atty",
"bitflags",
@ -976,24 +976,34 @@ dependencies = [
"os_str_bytes",
"strsim 0.10.0",
"termcolor",
"textwrap 0.12.1",
"unicode-width",
"vec_map",
"textwrap 0.15.0",
]
[[package]]
name = "clap_derive"
version = "3.0.0-beta.2"
version = "3.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
dependencies = [
"heck",
"heck 0.4.0",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "cli"
version = "0.1.0"
dependencies = [
"anyhow",
"clap 3.1.8",
"core-foundation",
"core-services",
"ipc-channel",
"serde",
]
[[package]]
name = "client"
version = "0.1.0"
@ -1087,7 +1097,7 @@ dependencies = [
"async-trait",
"async-tungstenite",
"base64 0.13.0",
"clap 3.0.0-beta.2",
"clap 3.1.8",
"client",
"collections",
"comrak",
@ -1272,6 +1282,15 @@ dependencies = [
"libc",
]
[[package]]
name = "core-services"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b344b958cae90858bf6086f49599ecc5ec8698eacad0ea155509ba11fab347"
dependencies = [
"core-foundation",
]
[[package]]
name = "core-text"
version = "19.2.0"
@ -1326,6 +1345,16 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "crossbeam-channel"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
dependencies = [
"crossbeam-utils 0.7.2",
"maybe-uninit",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.0"
@ -1333,7 +1362,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
]
[[package]]
@ -1344,7 +1373,7 @@ checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-epoch",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
]
[[package]]
@ -1354,7 +1383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d60ab4a8dba064f2fbb5aa270c28da5cf4bbd0e72dae1140a6b0353a779dbe00"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
"lazy_static",
"loom",
"memoffset",
@ -1368,7 +1397,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f6cb3c7f5b8e51bc3ebb73a2327ad4abdbd119dc13223f14f961d2f38486756"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
"autocfg 1.0.1",
"cfg-if 0.1.10",
"lazy_static",
]
[[package]]
@ -1472,7 +1512,7 @@ dependencies = [
"openssl-sys",
"schannel",
"socket2 0.4.0",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -1488,7 +1528,7 @@ dependencies = [
"openssl-sys",
"pkg-config",
"vcpkg",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -1634,7 +1674,7 @@ checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780"
dependencies = [
"libc",
"redox_users",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -1645,7 +1685,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -1668,7 +1708,7 @@ checksum = "439a1c2ba5611ad3ed731280541d36d2e9c4ac5e7fb818a27b604bdc5a6aa65b"
dependencies = [
"lazy_static",
"libc",
"winapi",
"winapi 0.3.9",
"wio",
]
@ -1865,9 +1905,9 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fastrand"
version = "1.4.0"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3"
checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
dependencies = [
"instant",
]
@ -1985,7 +2025,7 @@ dependencies = [
"pathfinder_simd",
"servo-fontconfig",
"walkdir",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -2070,6 +2110,22 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
dependencies = [
"bitflags",
"fuchsia-zircon-sys",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "funty"
version = "1.1.0"
@ -2201,7 +2257,7 @@ dependencies = [
"libc",
"log",
"rustc_version",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -2449,6 +2505,12 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
version = "0.1.18"
@ -2608,7 +2670,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b287fb45c60bb826a0dc68ff08742b9d88a2fea13d6e0c286b3172065aaf878c"
dependencies = [
"crossbeam-utils",
"crossbeam-utils 0.8.2",
"globset",
"lazy_static",
"log",
@ -2673,6 +2735,34 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
dependencies = [
"libc",
]
[[package]]
name = "ipc-channel"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cb1d9211085f0ea6f1379d944b93c4d07e8207aa3bcf49f37eda12b85081887"
dependencies = [
"bincode",
"crossbeam-channel 0.4.4",
"fnv",
"lazy_static",
"libc",
"mio",
"rand 0.7.3",
"serde",
"tempfile",
"uuid",
"winapi 0.3.9",
]
[[package]]
name = "isahc"
version = "0.9.14"
@ -2680,7 +2770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2948a0ce43e2c2ef11d7edf6816508998d99e13badd1150be0914205df9388a"
dependencies = [
"bytes 0.5.6",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
"curl",
"curl-sys",
"flume",
@ -2797,6 +2887,16 @@ dependencies = [
"sha2 0.9.5",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "kurbo"
version = "0.8.1"
@ -2893,7 +2993,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a"
dependencies = [
"cfg-if 1.0.0",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -3031,6 +3131,12 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "md-5"
version = "0.9.1"
@ -3124,6 +3230,37 @@ dependencies = [
"autocfg 1.0.1",
]
[[package]]
name = "mio"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4"
dependencies = [
"cfg-if 0.1.10",
"fuchsia-zircon",
"fuchsia-zircon-sys",
"iovec",
"kernel32-sys",
"libc",
"log",
"miow",
"net2",
"slab",
"winapi 0.2.8",
]
[[package]]
name = "miow"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d"
dependencies = [
"kernel32-sys",
"net2",
"winapi 0.2.8",
"ws2_32-sys",
]
[[package]]
name = "multimap"
version = "0.8.3"
@ -3140,6 +3277,17 @@ dependencies = [
"socket2 0.3.19",
]
[[package]]
name = "net2"
version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae"
dependencies = [
"cfg-if 0.1.10",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "nom"
version = "5.1.2"
@ -3361,9 +3509,12 @@ dependencies = [
[[package]]
name = "os_str_bytes"
version = "2.4.0"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]]
name = "outline"
@ -3421,7 +3572,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -3647,7 +3798,7 @@ dependencies = [
"libc",
"log",
"wepoll-sys",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -3727,9 +3878,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]]
name = "proc-macro2"
version = "1.0.24"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [
"unicode-xid",
]
@ -3823,7 +3974,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "355f634b43cdd80724ee7848f95770e7e70eefa6dcf14fea676216573b8fd603"
dependencies = [
"bytes 1.0.1",
"heck",
"heck 0.3.3",
"itertools",
"log",
"multimap",
@ -3888,7 +4039,7 @@ dependencies = [
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -4005,9 +4156,9 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
dependencies = [
"crossbeam-channel",
"crossbeam-channel 0.5.0",
"crossbeam-deque",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
"lazy_static",
"num_cpus",
]
@ -4069,7 +4220,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -4109,7 +4260,7 @@ dependencies = [
"spin",
"untrusted",
"web-sys",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -4311,7 +4462,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
dependencies = [
"lazy_static",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -4791,7 +4942,7 @@ checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e"
dependencies = [
"cfg-if 1.0.0",
"libc",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -4801,7 +4952,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2"
dependencies = [
"libc",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -4875,9 +5026,9 @@ dependencies = [
"bytes 0.5.6",
"chrono",
"crc",
"crossbeam-channel",
"crossbeam-channel 0.5.0",
"crossbeam-queue",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
"either",
"futures-channel",
"futures-core",
@ -4923,9 +5074,9 @@ dependencies = [
"byteorder",
"bytes 1.0.1",
"crc",
"crossbeam-channel",
"crossbeam-channel 0.5.0",
"crossbeam-queue",
"crossbeam-utils",
"crossbeam-utils 0.8.2",
"dirs 3.0.1",
"either",
"futures-channel",
@ -4971,7 +5122,7 @@ dependencies = [
"dotenv",
"either",
"futures",
"heck",
"heck 0.3.3",
"lazy_static",
"proc-macro2",
"quote",
@ -4992,7 +5143,7 @@ dependencies = [
"dotenv",
"either",
"futures",
"heck",
"heck 0.3.3",
"once_cell",
"proc-macro2",
"quote",
@ -5191,9 +5342,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.67"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702"
checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d"
dependencies = [
"proc-macro2",
"quote",
@ -5230,16 +5381,16 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.2.0"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if 1.0.0",
"fastrand",
"libc",
"rand 0.8.3",
"redox_syscall",
"remove_dir_all",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -5283,12 +5434,9 @@ dependencies = [
[[package]]
name = "textwrap"
version = "0.12.1"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
dependencies = [
"unicode-width",
]
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "theme"
@ -5410,7 +5558,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -5425,7 +5573,7 @@ dependencies = [
"stdweb",
"time-macros",
"version_check",
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -5846,6 +5994,9 @@ name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom 0.2.2",
]
[[package]]
name = "value-bag"
@ -5916,7 +6067,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
dependencies = [
"same-file",
"winapi",
"winapi 0.3.9",
"winapi-util",
]
@ -6073,6 +6224,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]]
name = "winapi"
version = "0.3.9"
@ -6083,6 +6240,12 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
@ -6095,7 +6258,7 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -6110,7 +6273,7 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5"
dependencies = [
"winapi",
"winapi 0.3.9",
]
[[package]]
@ -6136,6 +6299,16 @@ dependencies = [
"util",
]
[[package]]
name = "ws2_32-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "wyz"
version = "0.2.0"

12
crates/cli/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0"
core-foundation = "0.9"
core-services = "0.2"
clap = { version = "3.1", features = ["derive"] }
ipc-channel = "0.16"
serde = { version = "1.0", features = ["derive"] }

95
crates/cli/src/main.rs Normal file
View File

@ -0,0 +1,95 @@
use anyhow::{anyhow, Result};
use clap::Parser;
use core_foundation::{
array::{CFArray, CFIndex},
string::kCFStringEncodingUTF8,
url::{CFURLCreateWithBytes, CFURL},
};
use core_services::{kLSLaunchDefaults, LSLaunchURLSpec, LSOpenFromURLSpec, TCFType};
use ipc_channel::ipc::IpcOneShotServer;
use serde::{Deserialize, Serialize};
use std::{path::PathBuf, process, ptr};
#[derive(Parser)]
#[clap(name = "zed")]
struct Args {
/// Wait for all of the given paths to be closed before exiting.
#[clap(short, long)]
wait: bool,
/// A sequence of space-separated paths that you want to open.
#[clap()]
paths: Vec<PathBuf>,
}
#[derive(Serialize, Deserialize)]
struct OpenResult {
exit_status: i32,
stdout_message: Option<String>,
stderr_message: Option<String>,
}
fn main() -> Result<()> {
let args = Args::parse();
let (server, server_name) = IpcOneShotServer::<OpenResult>::new()?;
let app_path = locate_app()?;
launch_app(app_path, args.paths, server_name)?;
let (_, result) = server.accept()?;
if let Some(message) = result.stdout_message {
println!("{}", message);
}
if let Some(message) = result.stderr_message {
eprintln!("{}", message);
}
process::exit(result.exit_status)
}
fn locate_app() -> Result<PathBuf> {
Ok("/Applications/Zed.app".into())
}
fn launch_app(app_path: PathBuf, paths_to_open: Vec<PathBuf>, server_name: String) -> Result<()> {
let status = unsafe {
let app_url =
CFURL::from_path(&app_path, true).ok_or_else(|| anyhow!("invalid app path"))?;
let mut urls_to_open = paths_to_open
.into_iter()
.map(|path| {
CFURL::from_path(&path, true).ok_or_else(|| anyhow!("{:?} is invalid", path))
})
.collect::<Result<Vec<_>>>()?;
let server_url = format!("zed_cli_response://{server_name}");
urls_to_open.push(CFURL::wrap_under_create_rule(CFURLCreateWithBytes(
ptr::null(),
server_url.as_ptr(),
server_url.len() as CFIndex,
kCFStringEncodingUTF8,
ptr::null(),
)));
let urls_to_open = CFArray::from_copyable(
&urls_to_open
.iter()
.map(|url| url.as_concrete_TypeRef())
.collect::<Vec<_>>(),
);
LSOpenFromURLSpec(
&LSLaunchURLSpec {
appURL: app_url.as_concrete_TypeRef(),
itemURLs: urls_to_open.as_concrete_TypeRef(),
passThruParams: ptr::null(),
launchFlags: kLSLaunchDefaults,
asyncRefCon: ptr::null_mut(),
},
ptr::null_mut(),
)
};
if status == 0 {
Ok(())
} else {
Err(anyhow!("cannot start {:?}", app_path))
}
}

View File

@ -22,7 +22,7 @@ async-std = { version = "1.8.0", features = ["attributes"] }
async-trait = "0.1.50"
async-tungstenite = "0.16"
base64 = "0.13"
clap = "=3.0.0-beta.2"
clap = "3.1"
comrak = "0.10"
either = "1.6"
envy = "0.4.2"

View File

@ -94,6 +94,10 @@ unsafe fn build_classes() {
sel!(application:openFiles:),
open_files as extern "C" fn(&mut Object, Sel, id, id),
);
decl.add_method(
sel!(application:openURLs:),
open_urls as extern "C" fn(&mut Object, Sel, id, id),
);
decl.register()
}
}
@ -702,6 +706,30 @@ extern "C" fn open_files(this: &mut Object, _: Sel, _: id, paths: id) {
}
}
extern "C" fn open_urls(this: &mut Object, _: Sel, _: id, paths: id) {
let paths = unsafe {
(0..paths.count())
.into_iter()
.filter_map(|i| {
let path = paths.objectAtIndex(i);
match dbg!(
CStr::from_ptr(path.absoluteString().UTF8String() as *mut c_char).to_str()
) {
Ok(string) => Some(PathBuf::from(string)),
Err(err) => {
log::error!("error converting path to string: {}", err);
None
}
}
})
.collect::<Vec<_>>()
};
// let platform = unsafe { get_foreground_platform(this) };
// if let Some(callback) = platform.0.borrow_mut().open_files.as_mut() {
// callback(paths);
// }
}
extern "C" fn handle_menu_item(this: &mut Object, _: Sel, item: id) {
unsafe {
let platform = get_foreground_platform(this);