diff --git a/example/.directory/bar b/example/.directory/bar new file mode 100644 index 0000000..e69de29 diff --git a/example/.foo b/example/.foo new file mode 100644 index 0000000..e69de29 diff --git a/example/file_example b/example/file_example index 48aae6c..7c80add 100755 --- a/example/file_example +++ b/example/file_example @@ -1,5 +1,5 @@ #!/usr/bin/env python -# USAGE: hey' +# SUMMARY: hey' # START HELP # this is an example of a simple script written in python. # END HELP diff --git a/example/source_example b/example/source_example index 8946088..eb4917b 100755 --- a/example/source_example +++ b/example/source_example @@ -1,5 +1,5 @@ # SOURCE -# USAGE: an example for sourcing variables +# SUMMARY: an example for sourcing variables # START HELP # This is an example of a script that is sourced, rather # than executed. This means that anything you run in here diff --git a/src/commands/help.rs b/src/commands/help.rs index 752e587..6d824f9 100644 --- a/src/commands/help.rs +++ b/src/commands/help.rs @@ -18,7 +18,7 @@ pub fn help(root: &str, mut _args: Peekable>) -> io::Result commands_with_help.push(format!( " {}: {}", escape_slashes(&command), - escape_slashes(&script.usage_string) + escape_slashes(&script.summary_string) )) } return Ok(format!( diff --git a/src/commands/script.rs b/src/commands/script.rs index 4fd9e5a..ef65ec7 100644 --- a/src/commands/script.rs +++ b/src/commands/script.rs @@ -21,7 +21,7 @@ pub struct Script { pub help_string: String, /// the string that should be used for /// usage information - pub usage_string: String, + pub summary_string: String, } impl Script { @@ -33,7 +33,7 @@ impl Script { let mut buffer = BufReader::new(body); let mut should_source = false; let mut help_string = String::new(); - let mut usage_string = String::new(); + let mut summary_string = String::new(); let mut line = String::new(); let mut consuming_help = false; loop { @@ -59,9 +59,9 @@ impl Script { should_source = true; } else if line.starts_with("# START HELP") { consuming_help = true; - } else if line.starts_with("# USAGE: ") { + } else if line.starts_with("# SUMMARY: ") { // 9 = prefix, -1 strips newline - usage_string.push_str(&line[9..(line.len() - 1)]); + summary_string.push_str(&line[11..(line.len() - 1)]); } else if !line.starts_with("#!") { // if a shebang is encountered, we skip. // as it can indicate the command to run the script with. @@ -74,7 +74,7 @@ impl Script { path, should_source, help_string, - usage_string, + summary_string, } } @@ -137,4 +137,4 @@ impl Script { } } } -} +} \ No newline at end of file diff --git a/src/commands/tests.rs b/src/commands/tests.rs index d9f3506..eca69e7 100644 --- a/src/commands/tests.rs +++ b/src/commands/tests.rs @@ -10,7 +10,7 @@ fn test_should_source() { "# SOURCE cd /tmp/ ", - )) as Box, + )) as Box, ); assert_eq!(script.should_source, true); } @@ -25,7 +25,7 @@ fn test_should_not_source() { "#!/usr/bin/env bash echo foo ", - )) as Box, + )) as Box, ); assert_eq!(script.should_source, false); } @@ -40,7 +40,7 @@ fn test_help() { # foo bar baz # END HELP ", - )) as Box, + )) as Box, ); assert_eq!(&script.help_string, "foo bar baz\n"); } @@ -51,12 +51,12 @@ fn test_usage() { String::from("./example/foo"), Box::new(Cursor::new( "#!/usr/bin/env bash -# USAGE: this is the usage +# SUMMARY: this is the usage # START HELP # foo bar baz # END HELP ", - )) as Box, + )) as Box, ); - assert_eq!(&script.usage_string, "this is the usage"); + assert_eq!(&script.summary_string, "this is the usage"); } diff --git a/src/directory.rs b/src/directory.rs index 9fa7dca..6ac8dcc 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -41,6 +41,16 @@ pub fn scan_directory( /// returns if this directory should be considered by tome pub fn is_tome_script_directory(dir: &Path) -> bool { let mut tomeignore_location = dir.to_path_buf(); + // ignore dot directories + if tomeignore_location + .file_name() + .unwrap_or_default() + .to_str() + .unwrap_or_default() + .starts_with(".") + { + return false; + } tomeignore_location.push(".tomeignore"); return !tomeignore_location.exists(); } diff --git a/src/main.rs b/src/main.rs index 857f2d4..b95e97d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::{env::args, fs, path::PathBuf}; mod commands; mod directory; +mod script; #[cfg(test)] mod tests; @@ -100,13 +101,23 @@ pub fn execute(raw_args: Vec) -> Result { TargetType::Directory => match command_type { CommandType::Completion => { let mut result = vec![]; - let mut paths: Vec<_> = fs::read_dir(target.to_str().unwrap_or("")).unwrap().map(|r| r.unwrap()).collect(); + let mut paths: Vec<_> = fs::read_dir(target.to_str().unwrap_or("")) + .unwrap() + .map(|r| r.unwrap()) + .collect(); paths.sort_by_key(|f| f.path()); for path_buf in paths { let path = path_buf.path(); if path.is_dir() && !directory::is_tome_script_directory(&path) { continue; } + if path.is_file() + && !script::is_tome_script( + path_buf.file_name().to_str().unwrap_or_default(), + ) + { + continue; + } result.push(path.file_name().unwrap().to_str().unwrap_or("").to_owned()); } result.join(" ").to_owned() diff --git a/src/script.rs b/src/script.rs new file mode 100644 index 0000000..76da66f --- /dev/null +++ b/src/script.rs @@ -0,0 +1,4 @@ +// used to determine if the file is a valid script or not +pub fn is_tome_script(filename: &str) -> bool { + return !filename.starts_with("."); +} diff --git a/src/tests.rs b/src/tests.rs index 4269900..5a57a32 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -99,7 +99,8 @@ fn test_use_arg() { #[test] fn test_help_page() { let result = execute(_vec_str(vec!["tome", EXAMPLE_DIR])).unwrap(); - assert_eq!(result.matches("'\''").count(), 1); - assert_eq!(result.matches("'").count(), 3); + println!("{}", result); + assert_eq!(result.matches("'\\''").count(), 1); + assert_eq!(result.matches("'").count(), 5); assert!(result.contains("echo -e")); }