A cli program to easily handle .gitignore files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.3 KiB

  1. /*! Application-specific logic lives here */
  2. // Parts Copyright 2017-2019, Stephan Sokolow
  3. // Standard library imports
  4. use std::path::PathBuf;
  5. // 3rd-party crate imports
  6. use structopt::StructOpt;
  7. use log::{debug, error, info, trace, warn};
  8. // Local Imports
  9. use crate::errors::*;
  10. use crate::helpers::{BoilerplateOpts, HELP_TEMPLATE};
  11. use crate::validators::path_readable_file;
  12. /// The verbosity level when no `-q` or `-v` arguments are given, with `0` being `-q`
  13. pub const DEFAULT_VERBOSITY: u64 = 1;
  14. /// Command-line argument schema
  15. ///
  16. /// ## Relevant Conventions:
  17. ///
  18. /// * Make sure that there is a blank space between the `<name>` `<version>` line and the
  19. /// description text or the `--help` output won't comply with the platform conventions that
  20. /// `help2man` depends on to generate your manpage.
  21. /// (Specifically, it will mistake the `<name> <version>` line for part of the description.)
  22. /// * `StructOpt`'s default behaviour of including the author name in the `--help` output is an
  23. /// oddity among Linux commands and, if you don't disable it, you run the risk of people
  24. /// unfamiliar with `StructOpt` assuming that you are an egotistical person who made a conscious
  25. /// choice to add it.
  26. ///
  27. /// The proper standardized location for author information is the `AUTHOR` section which you
  28. /// can read about by typing `man help2man`.
  29. ///
  30. /// ## Cautions:
  31. /// * Subcommands do not inherit `template` and it must be re-specified for each one.
  32. /// ([clap-rs/clap#1184](https://github.com/clap-rs/clap/issues/1184))
  33. /// * Double-check that your choice of `about` or `long_about` is actually overriding this
  34. /// doc comment. The precedence is affected by things you wouldn't expect, such as the presence
  35. /// or absence of `template` and it's easy to wind up with this doc-comment as your `--help`
  36. /// ([TeXitoi/structopt#173](https://github.com/TeXitoi/structopt/issues/173))
  37. /// * Do not begin the description text for subcommands with `\n`. It will break the formatting
  38. /// in the top-level help output's list of subcommands.
  39. #[derive(StructOpt, Debug)]
  40. #[structopt(template = HELP_TEMPLATE,
  41. about = "TODO: Replace me with the description text for the command",
  42. global_setting = structopt::clap::AppSettings::ColoredHelp)]
  43. pub struct CliOpts {
  44. #[allow(clippy::missing_docs_in_private_items)] // StructOpt won't let us document this
  45. #[structopt(flatten)]
  46. pub boilerplate: BoilerplateOpts,
  47. // -- Arguments used by application-specific logic --
  48. /// File(s) to use as input
  49. ///
  50. /// **TODO:** Figure out if there's a way to only enforce constraints on this when not asking
  51. /// to dump completions.
  52. #[structopt(parse(from_os_str),
  53. validator_os = path_readable_file)]
  54. inpath: Vec<PathBuf>,
  55. }
  56. /// The actual `main()`
  57. pub fn main(opts: CliOpts) -> Result<()> {
  58. for inpath in opts.inpath {
  59. unimplemented!()
  60. }
  61. Ok(())
  62. }
  63. // Tests go below the code where they'll be out of the way when not the target of attention
  64. #[cfg(test)]
  65. mod tests {
  66. use super::CliOpts;
  67. // TODO: Unit test to verify that the doc comment on `CliOpts` isn't overriding the intended
  68. // about string.
  69. #[test]
  70. /// Test something
  71. fn test_something() {
  72. // TODO: Test something
  73. }
  74. }