Skip to main content

github_workflows_update/
cli.rs

1// Copyright (C) 2022 Leandro Lisboa Penz <lpenz@lpenz.org>
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4
5use clap::Parser;
6use clap::ValueEnum;
7
8#[derive(Parser, Debug)]
9#[command(
10    author,
11    version,
12    about = "Check github workflows for actions that can be updated",
13    long_about = "github-workflows-update reads all github workflow and checks the latest
14available versions of all github actions and workflow dispatches used, showing
15which ones can be updated and optionally updating them automatically."
16)]
17pub struct Cli {
18    /// Don't update the workflows, just print what would be done
19    #[clap(short = 'n', long = "dry-run")]
20    pub dryrun: bool,
21    /// Output format for the outdated action messages
22    #[clap(short = 'f', long, value_enum, value_parser)]
23    pub output_format: Option<OutputFormat>,
24    /// Return error if any outdated actions are found
25    #[clap(long)]
26    pub error_on_outdated: bool,
27}
28
29#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Default, Debug)]
30pub enum OutputFormat {
31    #[default]
32    Standard,
33    /// Generate messages as github action warnings
34    GithubWarning,
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40    use clap::CommandFactory;
41
42    #[test]
43    fn test_cli() {
44        Cli::command().debug_assert();
45    }
46
47    #[test]
48    fn test_parse_args() {
49        let args = Cli::parse_from(&["test", "-n", "-f", "github-warning", "--error-on-outdated"]);
50        assert!(args.dryrun);
51        assert_eq!(args.output_format, Some(OutputFormat::GithubWarning));
52        assert!(args.error_on_outdated);
53    }
54}