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 @@
11 #![cfg_attr(target_os = "linux", allow(dead_code))]
22
33 use anyhow::{anyhow, Context, Result};
4−use clap::Parser;
4+use clap::{Error, ErrorKind, Parser};
55 use cli::{CliRequest, CliResponse};
66 use serde::Deserialize;
77 use std::{
8+ env,
89 ffi::OsStr,
910 fs::{self, OpenOptions},
1011 io,
@@ -62,15 +63,15 @@ fn main() -> Result<()> { · 51 unmodified lines
6263 return Ok(());
6364 }
6465
65− for path in args
66− .paths_with_position
67− .iter()
68− .map(|path_with_position| &path_with_position.path_like)
69− {
70− if !path.exists() {
71− touch(path.as_path())?;
72− }
73− }
66+ // for path in args
67+ // .paths_with_position
68+ // .iter()
69+ // .map(|path_with_position| &path_with_position.path_like)
70+ // {
71+ // if !path.exists() {
72+ // touch(path.as_path())?;
73+ // }
74+ // }
7475
7576 let (tx, rx) = bundle.launch()?;
7677 let open_new_workspace = if args.new {
@@ -81,21 +82,35 @@ fn main() -> Result<()> { · 4 unmodified lines
8182 None
8283 };
8384
84− tx.send(CliRequest::Open {
85+ tx.send(dbg!(CliRequest::Open {
8586 paths: args
8687 .paths_with_position
8788 .into_iter()
8889 .map(|path_with_position| {
89− let path_with_position = path_with_position.map_path_like(|path| {
90− fs::canonicalize(&path)
91− .with_context(|| format!("path {path:?} canonicalization"))
92− })?;
90+ let path_with_position =
91+ path_with_position.map_path_like(|path| match fs::canonicalize(&path) {
92+ Ok(path) => Ok(path),
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+ })?;
93108 Ok(path_with_position.to_string(|path| path.display().to_string()))
94109 })
95110 .collect::<Result<_>>()?,
96111 wait: args.wait,
97112 open_new_workspace,
98− })?;
113+ }))?;
99114
100115 while let Ok(response) = rx.recv() {
101116 match response {