@smbcloud / cli / commits / f3c4498

add deploy

Seto Elkahfi committed Apr 18, 2025 at 16:11 UTC f3c449851fcb542214f70b42fe85cded5d8ccf0e
8 files changed +451 -63
.vscode/settings.json
+6 -1
@@ -1,3 +1,8 @@
1 {
2 - "rust-analyzer.server.path": null
2 + "rust-analyzer.server.path": null,
3 + "java.jdt.ls.java.home": "/Users/setoelka/.local/share/mise/installs/java/openjdk-21.0.2",
4 + "java.import.gradle.java.home": "/Users/setoelka/.local/share/mise/installs/java/openjdk-21.0.2",
5 + "debug.javascript.defaultRuntimeExecutable": {
6 + "pwa-node": "/Users/setoelka/.local/share/mise/shims/node"
7 + }
8 }
\ No newline at end of file
Cargo.lock
+229 -35
@@ -1,6 +1,6 @@
1 # This file is automatically @generated by Cargo.
2 # It is not intended for manual editing.
3 -version = 3
3 +version = 4
4
5 [[package]]
6 name = "addr2line"
@@ -173,10 +173,12 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b"
173
174 [[package]]
175 name = "cc"
176 -version = "1.2.6"
176 +version = "1.2.19"
177 source = "registry+https://github.com/rust-lang/crates.io-index"
178 -checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333"
178 +checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362"
179 dependencies = [
180 + "jobserver",
181 + "libc",
182 "shlex",
183 ]
184
@@ -313,7 +315,16 @@ version = "4.0.0"
315 source = "registry+https://github.com/rust-lang/crates.io-index"
316 checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
317 dependencies = [
316 - "dirs-sys",
318 + "dirs-sys 0.3.7",
319 +]
320 +
321 +[[package]]
322 +name = "dirs"
323 +version = "6.0.0"
324 +source = "registry+https://github.com/rust-lang/crates.io-index"
325 +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
326 +dependencies = [
327 + "dirs-sys 0.5.0",
328 ]
329
330 [[package]]
@@ -323,10 +334,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
334 checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
335 dependencies = [
336 "libc",
326 - "redox_users",
337 + "redox_users 0.4.6",
338 "winapi",
339 ]
340
341 +[[package]]
342 +name = "dirs-sys"
343 +version = "0.5.0"
344 +source = "registry+https://github.com/rust-lang/crates.io-index"
345 +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
346 +dependencies = [
347 + "libc",
348 + "option-ext",
349 + "redox_users 0.5.0",
350 + "windows-sys 0.59.0",
351 +]
352 +
353 [[package]]
354 name = "displaydoc"
355 version = "0.2.5"
@@ -471,6 +494,38 @@ version = "0.31.1"
494 source = "registry+https://github.com/rust-lang/crates.io-index"
495 checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
496
497 +[[package]]
498 +name = "git-url-parse"
499 +version = "0.4.5"
500 +source = "registry+https://github.com/rust-lang/crates.io-index"
501 +checksum = "68d7ff03a34ea818a59cf30c0d7aa55354925484fa30bcc4cb96d784ff07578f"
502 +dependencies = [
503 + "strum 0.26.3",
504 + "thiserror 1.0.69",
505 + "url",
506 +]
507 +
508 +[[package]]
509 +name = "git2"
510 +version = "0.20.1"
511 +source = "registry+https://github.com/rust-lang/crates.io-index"
512 +checksum = "5220b8ba44c68a9a7f7a7659e864dd73692e417ef0211bea133c7b74e031eeb9"
513 +dependencies = [
514 + "bitflags 2.6.0",
515 + "libc",
516 + "libgit2-sys",
517 + "log",
518 + "openssl-probe",
519 + "openssl-sys",
520 + "url",
521 +]
522 +
523 +[[package]]
524 +name = "glob"
525 +version = "0.3.2"
526 +source = "registry+https://github.com/rust-lang/crates.io-index"
527 +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
528 +
529 [[package]]
530 name = "h2"
531 version = "0.3.26"
@@ -797,11 +852,20 @@ version = "1.0.14"
852 source = "registry+https://github.com/rust-lang/crates.io-index"
853 checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
854
855 +[[package]]
856 +name = "jobserver"
857 +version = "0.1.32"
858 +source = "registry+https://github.com/rust-lang/crates.io-index"
859 +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
860 +dependencies = [
861 + "libc",
862 +]
863 +
864 [[package]]
865 name = "js-sys"
802 -version = "0.3.76"
866 +version = "0.3.77"
867 source = "registry+https://github.com/rust-lang/crates.io-index"
804 -checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7"
868 +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
869 dependencies = [
870 "once_cell",
871 "wasm-bindgen",
@@ -815,9 +879,23 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
879
880 [[package]]
881 name = "libc"
818 -version = "0.2.169"
882 +version = "0.2.172"
883 source = "registry+https://github.com/rust-lang/crates.io-index"
820 -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
884 +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
885 +
886 +[[package]]
887 +name = "libgit2-sys"
888 +version = "0.18.1+1.9.0"
889 +source = "registry+https://github.com/rust-lang/crates.io-index"
890 +checksum = "e1dcb20f84ffcdd825c7a311ae347cce604a6f084a767dec4a4929829645290e"
891 +dependencies = [
892 + "cc",
893 + "libc",
894 + "libssh2-sys",
895 + "libz-sys",
896 + "openssl-sys",
897 + "pkg-config",
898 +]
899
900 [[package]]
901 name = "libredox"
@@ -829,6 +907,32 @@ dependencies = [
907 "libc",
908 ]
909
910 +[[package]]
911 +name = "libssh2-sys"
912 +version = "0.3.1"
913 +source = "registry+https://github.com/rust-lang/crates.io-index"
914 +checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9"
915 +dependencies = [
916 + "cc",
917 + "libc",
918 + "libz-sys",
919 + "openssl-sys",
920 + "pkg-config",
921 + "vcpkg",
922 +]
923 +
924 +[[package]]
925 +name = "libz-sys"
926 +version = "1.1.22"
927 +source = "registry+https://github.com/rust-lang/crates.io-index"
928 +checksum = "8b70e7a7df205e92a1a4cd9aaae7898dac0aa555503cc0a649494d0d60e7651d"
929 +dependencies = [
930 + "cc",
931 + "libc",
932 + "pkg-config",
933 + "vcpkg",
934 +]
935 +
936 [[package]]
937 name = "linux-raw-sys"
938 version = "0.4.14"
@@ -1027,6 +1131,12 @@ dependencies = [
1131 "vcpkg",
1132 ]
1133
1134 +[[package]]
1135 +name = "option-ext"
1136 +version = "0.2.0"
1137 +source = "registry+https://github.com/rust-lang/crates.io-index"
1138 +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
1139 +
1140 [[package]]
1141 name = "overload"
1142 version = "0.1.1"
@@ -1127,7 +1237,18 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
1237 dependencies = [
1238 "getrandom",
1239 "libredox",
1130 - "thiserror",
1240 + "thiserror 1.0.69",
1241 +]
1242 +
1243 +[[package]]
1244 +name = "redox_users"
1245 +version = "0.5.0"
1246 +source = "registry+https://github.com/rust-lang/crates.io-index"
1247 +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
1248 +dependencies = [
1249 + "getrandom",
1250 + "libredox",
1251 + "thiserror 2.0.12",
1252 ]
1253
1254 [[package]]
@@ -1407,7 +1528,9 @@ dependencies = [
1528 "clap_mangen",
1529 "console",
1530 "dialoguer",
1410 - "dirs",
1531 + "dirs 4.0.0",
1532 + "git-url-parse",
1533 + "git2",
1534 "home",
1535 "log",
1536 "open",
@@ -1421,10 +1544,12 @@ dependencies = [
1544 "smbcloud-networking-project",
1545 "smbcloud-utils",
1546 "spinners",
1547 + "ssh2-config",
1548 "tokio",
1549 "tracing",
1550 "tracing-bunyan-formatter",
1551 "tracing-subscriber",
1552 + "url",
1553 "url-builder",
1554 ]
1555
@@ -1445,7 +1570,7 @@ version = "0.3.7"
1570 dependencies = [
1571 "anyhow",
1572 "async-trait",
1448 - "dirs",
1573 + "dirs 4.0.0",
1574 "home",
1575 "log",
1576 "maybe-async",
@@ -1453,7 +1578,7 @@ dependencies = [
1578 "serde",
1579 "serde_json",
1580 "smbcloud-model",
1456 - "thiserror",
1581 + "thiserror 1.0.69",
1582 "url-builder",
1583 ]
1584
@@ -1463,7 +1588,7 @@ version = "0.3.7"
1588 dependencies = [
1589 "anyhow",
1590 "async-trait",
1466 - "dirs",
1591 + "dirs 4.0.0",
1592 "home",
1593 "log",
1594 "maybe-async",
@@ -1472,7 +1597,7 @@ dependencies = [
1597 "serde_json",
1598 "smbcloud-model",
1599 "smbcloud-networking",
1475 - "thiserror",
1600 + "thiserror 1.0.69",
1601 ]
1602
1603 [[package]]
@@ -1480,7 +1605,7 @@ name = "smbcloud-utils"
1605 version = "0.3.7"
1606 dependencies = [
1607 "anyhow",
1483 - "dirs",
1608 + "dirs 4.0.0",
1609 "home",
1610 "log",
1611 "regex",
@@ -1491,9 +1616,9 @@ dependencies = [
1616
1617 [[package]]
1618 name = "socket2"
1494 -version = "0.5.8"
1619 +version = "0.5.9"
1620 source = "registry+https://github.com/rust-lang/crates.io-index"
1496 -checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8"
1621 +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef"
1622 dependencies = [
1623 "libc",
1624 "windows-sys 0.52.0",
@@ -1507,7 +1632,23 @@ checksum = "a0ef947f358b9c238923f764c72a4a9d42f2d637c46e059dbd319d6e7cfb4f82"
1632 dependencies = [
1633 "lazy_static",
1634 "maplit",
1510 - "strum",
1635 + "strum 0.24.1",
1636 +]
1637 +
1638 +[[package]]
1639 +name = "ssh2-config"
1640 +version = "0.5.4"
1641 +source = "registry+https://github.com/rust-lang/crates.io-index"
1642 +checksum = "27c8904276fd411f602a6d7e447cccb6f669068badf71359bc4564a5144a866b"
1643 +dependencies = [
1644 + "anyhow",
1645 + "bitflags 2.6.0",
1646 + "dirs 6.0.0",
1647 + "git2",
1648 + "glob",
1649 + "log",
1650 + "thiserror 2.0.12",
1651 + "wildmatch",
1652 ]
1653
1654 [[package]]
@@ -1528,7 +1669,16 @@ version = "0.24.1"
1669 source = "registry+https://github.com/rust-lang/crates.io-index"
1670 checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
1671 dependencies = [
1531 - "strum_macros",
1672 + "strum_macros 0.24.3",
1673 +]
1674 +
1675 +[[package]]
1676 +name = "strum"
1677 +version = "0.26.3"
1678 +source = "registry+https://github.com/rust-lang/crates.io-index"
1679 +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
1680 +dependencies = [
1681 + "strum_macros 0.26.4",
1682 ]
1683
1684 [[package]]
@@ -1544,6 +1694,19 @@ dependencies = [
1694 "syn 1.0.109",
1695 ]
1696
1697 +[[package]]
1698 +name = "strum_macros"
1699 +version = "0.26.4"
1700 +source = "registry+https://github.com/rust-lang/crates.io-index"
1701 +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
1702 +dependencies = [
1703 + "heck 0.5.0",
1704 + "proc-macro2",
1705 + "quote",
1706 + "rustversion",
1707 + "syn 2.0.93",
1708 +]
1709 +
1710 [[package]]
1711 name = "syn"
1712 version = "1.0.109"
@@ -1623,7 +1786,16 @@ version = "1.0.69"
1786 source = "registry+https://github.com/rust-lang/crates.io-index"
1787 checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
1788 dependencies = [
1626 - "thiserror-impl",
1789 + "thiserror-impl 1.0.69",
1790 +]
1791 +
1792 +[[package]]
1793 +name = "thiserror"
1794 +version = "2.0.12"
1795 +source = "registry+https://github.com/rust-lang/crates.io-index"
1796 +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
1797 +dependencies = [
1798 + "thiserror-impl 2.0.12",
1799 ]
1800
1801 [[package]]
@@ -1637,6 +1809,17 @@ dependencies = [
1809 "syn 2.0.93",
1810 ]
1811
1812 +[[package]]
1813 +name = "thiserror-impl"
1814 +version = "2.0.12"
1815 +source = "registry+https://github.com/rust-lang/crates.io-index"
1816 +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
1817 +dependencies = [
1818 + "proc-macro2",
1819 + "quote",
1820 + "syn 2.0.93",
1821 +]
1822 +
1823 [[package]]
1824 name = "thread_local"
1825 version = "1.1.8"
@@ -1864,6 +2047,7 @@ dependencies = [
2047 "form_urlencoded",
2048 "idna",
2049 "percent-encoding",
2050 + "serde",
2051 ]
2052
2053 [[package]]
@@ -1925,20 +2109,21 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
2109
2110 [[package]]
2111 name = "wasm-bindgen"
1928 -version = "0.2.99"
2112 +version = "0.2.100"
2113 source = "registry+https://github.com/rust-lang/crates.io-index"
1930 -checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396"
2114 +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
2115 dependencies = [
2116 "cfg-if",
2117 "once_cell",
2118 + "rustversion",
2119 "wasm-bindgen-macro",
2120 ]
2121
2122 [[package]]
2123 name = "wasm-bindgen-backend"
1939 -version = "0.2.99"
2124 +version = "0.2.100"
2125 source = "registry+https://github.com/rust-lang/crates.io-index"
1941 -checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79"
2126 +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
2127 dependencies = [
2128 "bumpalo",
2129 "log",
@@ -1950,9 +2135,9 @@ dependencies = [
2135
2136 [[package]]
2137 name = "wasm-bindgen-futures"
1953 -version = "0.4.49"
2138 +version = "0.4.50"
2139 source = "registry+https://github.com/rust-lang/crates.io-index"
1955 -checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2"
2140 +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61"
2141 dependencies = [
2142 "cfg-if",
2143 "js-sys",
@@ -1963,9 +2148,9 @@ dependencies = [
2148
2149 [[package]]
2150 name = "wasm-bindgen-macro"
1966 -version = "0.2.99"
2151 +version = "0.2.100"
2152 source = "registry+https://github.com/rust-lang/crates.io-index"
1968 -checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe"
2153 +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
2154 dependencies = [
2155 "quote",
2156 "wasm-bindgen-macro-support",
@@ -1973,9 +2158,9 @@ dependencies = [
2158
2159 [[package]]
2160 name = "wasm-bindgen-macro-support"
1976 -version = "0.2.99"
2161 +version = "0.2.100"
2162 source = "registry+https://github.com/rust-lang/crates.io-index"
1978 -checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2"
2163 +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
2164 dependencies = [
2165 "proc-macro2",
2166 "quote",
@@ -1986,20 +2171,29 @@ dependencies = [
2171
2172 [[package]]
2173 name = "wasm-bindgen-shared"
1989 -version = "0.2.99"
2174 +version = "0.2.100"
2175 source = "registry+https://github.com/rust-lang/crates.io-index"
1991 -checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
2176 +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
2177 +dependencies = [
2178 + "unicode-ident",
2179 +]
2180
2181 [[package]]
2182 name = "web-sys"
1995 -version = "0.3.76"
2183 +version = "0.3.77"
2184 source = "registry+https://github.com/rust-lang/crates.io-index"
1997 -checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc"
2185 +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2"
2186 dependencies = [
2187 "js-sys",
2188 "wasm-bindgen",
2189 ]
2190
2191 +[[package]]
2192 +name = "wildmatch"
2193 +version = "2.4.0"
2194 +source = "registry+https://github.com/rust-lang/crates.io-index"
2195 +checksum = "68ce1ab1f8c62655ebe1350f589c61e505cf94d385bc6a12899442d9081e71fd"
2196 +
2197 [[package]]
2198 name = "winapi"
2199 version = "0.3.9"
smbcloud-cli/Cargo.toml
+5 -1
@@ -3,7 +3,7 @@ name = "smbcloud-cli"
3 version = "0.3.7"
4 edition = "2021"
5 authors = ["Seto Elkahfi <hej@setoelkahfi.se>"]
6 -description = "Command line tool for creating and managing smbcloud resources."
6 +description = "Command line tool for creating and managing smbCloud resources."
7 license = "Apache-2.0"
8 repository = "https://github.com/smbcloudXYZ/smbcloud-cli"
9 documentation = "https://docs.smbcloud.xyz/cli"
@@ -24,6 +24,8 @@ dialoguer = "0.10.4"
24 dirs = "4.0.0"
25 home = "0.5.4"
26 log = "0.4.14"
27 +git2 = "0.20.1"
28 +ssh2-config = "^0.5"
29 open = "4.0.1"
30 regex = "1.3.1"
31 reqwest = { version = "0.11", features = ["json"] }
@@ -40,3 +42,5 @@ tracing = { version = "0.1.35", features = ["log"] }
42 tracing-bunyan-formatter = "0.3.3"
43 tracing-subscriber = { version = "0.3.14", features = ["registry", "env-filter"] }
44 url-builder = "0.1.1"
45 +url = { version = "2", features = ["serde"] }
46 +git-url-parse = "0.4.5"
smbcloud-cli/src/cli/mod.rs
+2 -25
@@ -32,29 +32,6 @@ pub enum Commands {
32 #[clap(subcommand)]
33 command: project::cli::Commands,
34 },
35 - /*
36 - #[clap(about = "Manage your Oten authentication app. Add, delete, edit. Need authentication.")]
37 - Oten {
38 - #[clap(subcommand)]
39 - command: app_oten::cli::Commands,
40 - },
41 - */
42 - // Function
43 - /*
44 - FunApp {
45 - #[clap(subcommand)]
46 - command: fun_app::cli::Commands,
47 - }, */
48 - // Package
49 - /*
50 - PktApp {
51 - #[clap(subcommand)]
52 - command: pkt_app::cli::Commands,
53 - }, */
54 - // Relational database
55 - /*
56 - RdbApp {
57 - #[clap(subcommand)]
58 - command: rdb_app::cli::Commands,
59 - }, */
35 + #[clap(about = "Deploy project. It will use deploy.sh script in the .smb folder.")]
36 + Deploy { },
37 }
smbcloud-cli/src/deploy/git.rs new
+1
@@ -0,0 +1 @@
1 +
smbcloud-cli/src/deploy/mod.rs new
+205
@@ -0,0 +1,205 @@
1 +mod git;
2 +
3 +use std::{fs::File, io::BufReader};
4 +
5 +use crate::cli::CommandResult;
6 +use anyhow::Result;
7 +use console::style;
8 +use git2::{Cred, PushOptions, RemoteCallbacks, Repository};
9 +use git_url_parse::{GitUrl, Scheme};
10 +use spinners::Spinner;
11 +use ssh2_config::{ParseRule, SshConfig};
12 +
13 +pub async fn process_deploy() -> Result<CommandResult> {
14 + println!("Deploying your app...");
15 + let mut spinner = Spinner::new(
16 + spinners::Spinners::SimpleDotsScrolling,
17 + style("Deploying...").green().bold().to_string(),
18 + );
19 +
20 + let repo = match Repository::open(".") {
21 + Ok(repo) => repo,
22 + Err(_) => {
23 + spinner.stop_and_persist("😩", "No git repository found.".to_owned());
24 + return Ok(CommandResult {
25 + spinner,
26 + symbol: "😩".to_owned(),
27 + msg: "No git repository found. Init with `git init` command.".to_owned(),
28 + });
29 + }
30 + };
31 +
32 + let _main_branch = match repo.head() {
33 + Ok(branch) => branch,
34 + Err(_) => {
35 + spinner.stop_and_persist("😩", "No main branch found.".to_owned());
36 + return Ok(CommandResult {
37 + spinner,
38 + symbol: "😩".to_owned(),
39 + msg: "No main branch found. Create with `git checkout -b <branch>` command."
40 + .to_owned(),
41 + });
42 + }
43 + };
44 + let mut origin = match repo.find_remote("origin") {
45 + Ok(remote) => remote,
46 + Err(_) => {
47 + spinner.stop_and_persist("😩", "No remote repository found.".to_owned());
48 + return Ok(CommandResult {
49 + spinner,
50 + symbol: "😩".to_owned(),
51 + msg: "No remote repository found. Add with `git remote add origin <url>` command."
52 + .to_owned(),
53 + });
54 + }
55 + };
56 + let remote_url = match origin.url() {
57 + Some(url) => url,
58 + None => {
59 + spinner.stop_and_persist("😩", "No remote URL found.".to_owned());
60 + return Ok(CommandResult {
61 + spinner,
62 + symbol: "😩".to_owned(),
63 + msg: "No remote URL found. Add with `git remote add origin <url>` command."
64 + .to_owned(),
65 + });
66 + }
67 + };
68 + //println!("Remote URL: {:#?}", remote_url);
69 + let parsed_url = match GitUrl::parse(remote_url) {
70 + Ok(url) => url,
71 + Err(e) => {
72 + spinner.stop_and_persist("😩", e.to_string());
73 + return Ok(CommandResult {
74 + spinner,
75 + symbol: "😩".to_owned(),
76 + msg: "Invalid remote URL.".to_owned(),
77 + });
78 + }
79 + };
80 + //println!("Parsed URL: {:#?}", parsed_url);
81 + match parsed_url.scheme {
82 + Scheme::Ssh => {
83 + println!("SSH URL: {:#?}", parsed_url);
84 + }
85 + _ => {
86 + // Only support ssh for now
87 + return Ok(CommandResult {
88 + spinner,
89 + symbol: "😩".to_owned(),
90 + msg: "Only ssh is supported.".to_owned(),
91 + });
92 + }
93 + };
94 +
95 + // Get ssh config from host
96 + let host = match parsed_url.host {
97 + Some(host) => host,
98 + None => {
99 + spinner.stop_and_persist("😩", "No host found.".to_owned());
100 + return Ok(CommandResult {
101 + spinner,
102 + symbol: "😩".to_owned(),
103 + msg: "No host found.".to_owned(),
104 + });
105 + }
106 + };
107 +
108 + // get ssh_config
109 + let ssh_config_file = match home::home_dir() {
110 + Some(home) => {
111 + let ssh_config_path = home.join(".ssh/config");
112 + if ssh_config_path.exists() {
113 + // println!("SSH config path: {:#?}", ssh_config_path);
114 + // Open the file and read it
115 + let file =
116 + File::open(ssh_config_path.clone()).expect("Unable to open ssh config file");
117 + file
118 + } else {
119 + spinner.stop_and_persist("😩", "No ssh config found.".to_owned());
120 + return Ok(CommandResult {
121 + spinner,
122 + symbol: "😩".to_owned(),
123 + msg: "No ssh config found.".to_owned(),
124 + });
125 + }
126 + }
127 + None => {
128 + spinner.stop_and_persist("😩", "No home".to_owned());
129 + return Ok(CommandResult {
130 + spinner,
131 + symbol: "😩".to_owned(),
132 + msg: "No home directory found.".to_owned(),
133 + });
134 + }
135 + };
136 + //println!("SSH config path: {:#?}", ssh_config_file);
137 + let mut reader = BufReader::new(ssh_config_file);
138 + let config = SshConfig::default()
139 + .parse(&mut reader, ParseRule::STRICT)
140 + .expect("Failed to parse ssh config file");
141 + //println!("SSH config: {:#?}", config);
142 +
143 + // Get the host config
144 + let host_config = config.query(host);
145 + //println!("Host config: {:#?}", host_config);
146 + // get identity_file
147 + let identity_files = match host_config.identity_file {
148 + Some(identity_files) => {
149 + println!("Identity file: {:#?}", identity_files);
150 + identity_files
151 + }
152 + None => {
153 + spinner.stop_and_persist("😩", "No identity file found.".to_owned());
154 + return Ok(CommandResult {
155 + spinner,
156 + symbol: "😩".to_owned(),
157 + msg: "No identity files found.".to_owned(),
158 + });
159 + }
160 + };
161 + //println!("Identity files: {:#?}", identity_files);
162 + // get identity_file
163 + let identity_file = match identity_files.first() {
164 + Some(identity_file) => {
165 + //println!("Identity file: {:#?}", identity_file);
166 + identity_file
167 + }
168 + None => {
169 + spinner.stop_and_persist("😩", "No identity file found.".to_owned());
170 + return Ok(CommandResult {
171 + spinner,
172 + symbol: "😩".to_owned(),
173 + msg: "No identity file found.".to_owned(),
174 + });
175 + }
176 + };
177 + let mut push_opts = PushOptions::new();
178 + let mut callbacks = RemoteCallbacks::new();
179 + // Set the credentials
180 + callbacks.credentials(|_url, _username_from_url, _allowed_types| {
181 + Cred::ssh_key("git", None, identity_file, None)
182 + });
183 + push_opts.remote_callbacks(callbacks);
184 +
185 + let _push = match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
186 + Ok(_) => {}
187 + Err(e) => {
188 + println!("Failed to push to remote: {:#?}", e);
189 + spinner.stop_and_persist("😩", e.to_string());
190 + return Ok(CommandResult {
191 + spinner,
192 + symbol: "😩".to_owned(),
193 + msg: e.to_string(),
194 + });
195 + }
196 + };
197 +
198 + spinner.stop_and_persist("✅", "Your app has been deployed successfully.".to_owned());
199 +
200 + Ok(CommandResult {
201 + spinner,
202 + symbol: "🚀".to_owned(),
203 + msg: "Your app has been deployed successfully.".to_owned(),
204 + })
205 +}
smbcloud-cli/src/lib.rs
+1
@@ -1,3 +1,4 @@
1 pub mod account;
2 pub mod cli;
3 pub mod project;
4 +pub mod deploy;
smbcloud-cli/src/main.rs
+2 -1
@@ -6,6 +6,7 @@ use smbcloud_cli::{
6 account::process_account,
7 cli::{Cli, Commands},
8 project::process_project,
9 + deploy::process_deploy,
10 };
11 use std::{
12 fs::{create_dir_all, OpenOptions},
@@ -99,6 +100,6 @@ async fn run() -> Result<CommandResult> {
100 match cli.command {
101 Commands::Account { command } => process_account(command).await,
102 Commands::Project { command } => process_project(command).await,
102 - //Commands::Oten { command } => process_auth_app(command).await,
103 + Commands::Deploy { } => process_deploy().await,
104 }
105 }