History

TEMP

Conrad Irwin committed 2 years ago

Commit f00a0e11 parent 758e7071 file · +31 −16Browse files

Unified · Split

crates/cli/src/main.rs+31−16
@@ -1,10 +1,11 @@
1#![cfg_attr(target_os = "linux", allow(dead_code))]1#![cfg_attr(target_os = "linux", allow(dead_code))]
2 2
3use anyhow::{anyhow, Context, Result};3use anyhow::{anyhow, Context, Result};
4use clap::Parser;4use clap::{Error, ErrorKind, Parser};
5use cli::{CliRequest, CliResponse};5use cli::{CliRequest, CliResponse};
6use serde::Deserialize;6use serde::Deserialize;
7use std::{7use std::{
8 env,
8 ffi::OsStr,9 ffi::OsStr,
9 fs::{self, OpenOptions},10 fs::{self, OpenOptions},
10 io,11 io,
@@ -62,15 +63,15 @@ fn main() -> Result<()> { · 51 unmodified lines
62 return Ok(());63 return Ok(());
63 }64 }
64 65
65 for path in args66 // for path in args
66 .paths_with_position67 // .paths_with_position
67 .iter()68 // .iter()
68 .map(|path_with_position| &path_with_position.path_like)69 // .map(|path_with_position| &path_with_position.path_like)
69 {70 // {
70 if !path.exists() {71 // if !path.exists() {
71 touch(path.as_path())?;72 // touch(path.as_path())?;
72 }73 // }
73 }74 // }
74 75
75 let (tx, rx) = bundle.launch()?;76 let (tx, rx) = bundle.launch()?;
76 let open_new_workspace = if args.new {77 let open_new_workspace = if args.new {
@@ -81,21 +82,35 @@ fn main() -> Result<()> { · 4 unmodified lines
81 None82 None
82 };83 };
83 84
84 tx.send(CliRequest::Open {85 tx.send(dbg!(CliRequest::Open {
85 paths: args86 paths: args
86 .paths_with_position87 .paths_with_position
87 .into_iter()88 .into_iter()
88 .map(|path_with_position| {89 .map(|path_with_position| {
89 let path_with_position = path_with_position.map_path_like(|path| {90 let path_with_position =
90 fs::canonicalize(&path)91 path_with_position.map_path_like(|path| match fs::canonicalize(&path) {
91 .with_context(|| format!("path {path:?} canonicalization"))92 Ok(path) => Ok(path),
92 })?;93 Err(e) => {
94 if let Some(mut parent) = path.parent() {
95 let curdir = env::current_dir()?;
96 if parent == Path::new("") {
97 parent = &curdir;
98 }
99 match fs::canonicalize(parent) {
100 Ok(parent) => Ok(parent.join(path.file_name().unwrap())),
101 Err(_) => Err(e),
102 }
103 } else {
104 Err(e)
105 }
106 }
107 })?;
93 Ok(path_with_position.to_string(|path| path.display().to_string()))108 Ok(path_with_position.to_string(|path| path.display().to_string()))
94 })109 })
95 .collect::<Result<_>>()?,110 .collect::<Result<_>>()?,
96 wait: args.wait,111 wait: args.wait,
97 open_new_workspace,112 open_new_workspace,
98 })?;113 }))?;
99 114
100 while let Ok(response) = rx.recv() {115 while let Ok(response) = rx.recv() {
101 match response {116 match response {