fixed compiler warnings
This commit is contained in:
@@ -114,7 +114,7 @@ pub fn autocmd(node: Node) -> ShResult<()> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::state::{self, AutoCmdKind, read_logic, write_logic};
|
use crate::state::{self, AutoCmdKind, read_logic};
|
||||||
use crate::testutil::{TestGuard, test_input};
|
use crate::testutil::{TestGuard, test_input};
|
||||||
|
|
||||||
// ===================== Registration =====================
|
// ===================== Registration =====================
|
||||||
@@ -253,7 +253,7 @@ mod tests {
|
|||||||
"on-exit",
|
"on-exit",
|
||||||
];
|
];
|
||||||
for kind in kinds {
|
for kind in kinds {
|
||||||
test_input(&format!("autocmd {kind} 'true'")).unwrap();
|
test_input(format!("autocmd {kind} 'true'")).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use nix::{libc::STDOUT_FILENO, unistd::write};
|
|||||||
use yansi::Color;
|
use yansi::Color;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
libsh::{error::{ShErr, ShErrKind, ShResult, next_color}, sys::TTY_FILENO},
|
libsh::error::{ShErr, ShErrKind, ShResult, next_color},
|
||||||
parse::{NdRule, Node, execute::prepare_argv, lex::Span},
|
parse::{NdRule, Node, execute::prepare_argv, lex::Span},
|
||||||
procio::borrow_fd,
|
procio::borrow_fd,
|
||||||
state::{self, read_meta, write_meta},
|
state::{self, read_meta, write_meta},
|
||||||
|
|||||||
@@ -368,6 +368,25 @@ pub fn map(node: Node) -> ShResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_map_opts(opts: Vec<Opt>) -> MapOpts {
|
||||||
|
let mut map_opts = MapOpts {
|
||||||
|
flags: MapFlags::empty(),
|
||||||
|
};
|
||||||
|
|
||||||
|
for opt in opts {
|
||||||
|
match opt {
|
||||||
|
Opt::Short('r') => map_opts.flags |= MapFlags::REMOVE,
|
||||||
|
Opt::Short('j') => map_opts.flags |= MapFlags::JSON,
|
||||||
|
Opt::Short('k') => map_opts.flags |= MapFlags::KEYS,
|
||||||
|
Opt::Short('l') => map_opts.flags |= MapFlags::LOCAL,
|
||||||
|
Opt::Long(ref s) if s == "pretty" => map_opts.flags |= MapFlags::PRETTY,
|
||||||
|
Opt::Short('F') => map_opts.flags |= MapFlags::FUNC,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map_opts
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{MapNode, MapFlags, get_map_opts};
|
use super::{MapNode, MapFlags, get_map_opts};
|
||||||
@@ -601,22 +620,3 @@ mod tests {
|
|||||||
assert_eq!(state::get_status(), 0);
|
assert_eq!(state::get_status(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_map_opts(opts: Vec<Opt>) -> MapOpts {
|
|
||||||
let mut map_opts = MapOpts {
|
|
||||||
flags: MapFlags::empty(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for opt in opts {
|
|
||||||
match opt {
|
|
||||||
Opt::Short('r') => map_opts.flags |= MapFlags::REMOVE,
|
|
||||||
Opt::Short('j') => map_opts.flags |= MapFlags::JSON,
|
|
||||||
Opt::Short('k') => map_opts.flags |= MapFlags::KEYS,
|
|
||||||
Opt::Short('l') => map_opts.flags |= MapFlags::LOCAL,
|
|
||||||
Opt::Long(ref s) if s == "pretty" => map_opts.flags |= MapFlags::PRETTY,
|
|
||||||
Opt::Short('F') => map_opts.flags |= MapFlags::FUNC,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
map_opts
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -341,6 +341,30 @@ pub fn read_key(node: Node) -> ShResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_read_key_opts(opts: Vec<Opt>) -> ShResult<ReadKeyOpts> {
|
||||||
|
let mut read_key_opts = ReadKeyOpts {
|
||||||
|
var_name: None,
|
||||||
|
char_whitelist: None,
|
||||||
|
char_blacklist: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
for opt in opts {
|
||||||
|
match opt {
|
||||||
|
Opt::ShortWithArg('v', var_name) => read_key_opts.var_name = Some(var_name),
|
||||||
|
Opt::ShortWithArg('w', char_whitelist) => read_key_opts.char_whitelist = Some(char_whitelist),
|
||||||
|
Opt::ShortWithArg('b', char_blacklist) => read_key_opts.char_blacklist = Some(char_blacklist),
|
||||||
|
_ => {
|
||||||
|
return Err(ShErr::simple(
|
||||||
|
ShErrKind::ExecFail,
|
||||||
|
format!("read_key: Unexpected flag '{opt}'"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(read_key_opts)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::state::{self, read_vars, write_vars, VarFlags, VarKind};
|
use crate::state::{self, read_vars, write_vars, VarFlags, VarKind};
|
||||||
@@ -468,27 +492,3 @@ mod tests {
|
|||||||
assert_eq!(flags.delim, b',');
|
assert_eq!(flags.delim, b',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_read_key_opts(opts: Vec<Opt>) -> ShResult<ReadKeyOpts> {
|
|
||||||
let mut read_key_opts = ReadKeyOpts {
|
|
||||||
var_name: None,
|
|
||||||
char_whitelist: None,
|
|
||||||
char_blacklist: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
for opt in opts {
|
|
||||||
match opt {
|
|
||||||
Opt::ShortWithArg('v', var_name) => read_key_opts.var_name = Some(var_name),
|
|
||||||
Opt::ShortWithArg('w', char_whitelist) => read_key_opts.char_whitelist = Some(char_whitelist),
|
|
||||||
Opt::ShortWithArg('b', char_blacklist) => read_key_opts.char_blacklist = Some(char_blacklist),
|
|
||||||
_ => {
|
|
||||||
return Err(ShErr::simple(
|
|
||||||
ShErrKind::ExecFail,
|
|
||||||
format!("read_key: Unexpected flag '{opt}'"),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(read_key_opts)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use ariadne::Fmt;
|
use ariadne::Fmt;
|
||||||
use nix::sys::resource::{Resource, getrlimit, setrlimit};
|
use nix::sys::resource::{Resource, getrlimit, setrlimit};
|
||||||
use yansi::Color;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
getopt::{Opt, OptSpec, get_opts_from_tokens, get_opts_from_tokens_strict}, libsh::error::{ShErr, ShErrKind, ShResult, ShResultExt, next_color}, parse::{NdRule, Node, execute::prepare_argv}, prelude::*, state::{self}
|
getopt::{Opt, OptSpec, get_opts_from_tokens_strict}, libsh::error::{ShErr, ShErrKind, ShResult, ShResultExt, next_color}, parse::{NdRule, Node}, state::{self}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn ulimit_opt_spec() -> [OptSpec;5] {
|
fn ulimit_opt_spec() -> [OptSpec;5] {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use crate::{
|
|||||||
libsh::{
|
libsh::{
|
||||||
error::{ShErr, ShErrKind, ShResult},
|
error::{ShErr, ShErrKind, ShResult},
|
||||||
sys::TTY_FILENO,
|
sys::TTY_FILENO,
|
||||||
term::{Style, Styled},
|
|
||||||
},
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
procio::{IoMode, borrow_fd},
|
procio::{IoMode, borrow_fd},
|
||||||
|
|||||||
@@ -333,6 +333,7 @@ pub fn borrow_fd<'f>(fd: i32) -> BorrowedFd<'f> {
|
|||||||
unsafe { BorrowedFd::borrow_raw(fd) }
|
unsafe { BorrowedFd::borrow_raw(fd) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PipeFrames = Map<PipeGenerator, fn((Option<Redir>, Option<Redir>)) -> IoFrame>;
|
||||||
pub struct PipeGenerator {
|
pub struct PipeGenerator {
|
||||||
num_cmds: usize,
|
num_cmds: usize,
|
||||||
cursor: usize,
|
cursor: usize,
|
||||||
@@ -347,7 +348,7 @@ impl PipeGenerator {
|
|||||||
last_rpipe: None,
|
last_rpipe: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn as_io_frames(self) -> Map<Self, fn((Option<Redir>, Option<Redir>)) -> IoFrame> {
|
pub fn as_io_frames(self) -> PipeFrames {
|
||||||
self.map(|(r, w)| {
|
self.map(|(r, w)| {
|
||||||
let mut frame = IoFrame::new();
|
let mut frame = IoFrame::new();
|
||||||
if let Some(r) = r {
|
if let Some(r) = r {
|
||||||
|
|||||||
@@ -472,7 +472,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{state, testutil::TestGuard};
|
use crate::{state, testutil::TestGuard};
|
||||||
use scopeguard::guard;
|
use scopeguard::guard;
|
||||||
use std::{env, fs, path::Path, sync::Mutex};
|
use std::{env, fs, path::Path};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
fn with_env_var(key: &str, val: &str) -> impl Drop {
|
fn with_env_var(key: &str, val: &str) -> impl Drop {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::{
|
|||||||
fmt::{Debug, Write},
|
fmt::{Debug, Write},
|
||||||
io::{BufRead, BufReader, Read},
|
io::{BufRead, BufReader, Read},
|
||||||
os::fd::{AsFd, BorrowedFd, RawFd},
|
os::fd::{AsFd, BorrowedFd, RawFd},
|
||||||
sync::Arc, time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use nix::{
|
use nix::{
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ pub struct TestGuard {
|
|||||||
old_cwd: PathBuf,
|
old_cwd: PathBuf,
|
||||||
saved_env: HashMap<String, String>,
|
saved_env: HashMap<String, String>,
|
||||||
pty_master: OwnedFd,
|
pty_master: OwnedFd,
|
||||||
pty_slave: OwnedFd,
|
_pty_slave: OwnedFd,
|
||||||
|
|
||||||
cleanups: Vec<Box<dyn FnOnce()>>
|
cleanups: Vec<Box<dyn FnOnce()>>
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ impl TestGuard {
|
|||||||
old_cwd,
|
old_cwd,
|
||||||
saved_env,
|
saved_env,
|
||||||
pty_master,
|
pty_master,
|
||||||
pty_slave,
|
_pty_slave: pty_slave,
|
||||||
cleanups: vec![],
|
cleanups: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user