Repository: j178/prefligit (language: python)

Issue:
pre-commit sample-config



Discussion / hints:

Fix patch:
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 8ee5319..cfee2d2 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -9,11 +9,13 @@ use crate::config::{HookType, Stage};
 mod clean;
 mod install;
 mod run;
+mod sample_config;
 mod validate;
 
 pub(crate) use clean::clean;
 pub(crate) use install::{install, uninstall};
 pub(crate) use run::run;
+pub(crate) use sample_config::sample_config;
 pub(crate) use validate::{validate_configs, validate_manifest};
 
 #[derive(Copy, Clone)]
diff --git a/src/cli/sample_config.rs b/src/cli/sample_config.rs
new file mode 100644
index 0000000..a7996c2
--- /dev/null
+++ b/src/cli/sample_config.rs
@@ -0,0 +1,20 @@
+use crate::cli::ExitStatus;
+
+static SAMPLE_CONFIG: &str = "\
+# See https://pre-commit.com for more information
+# See https://pre-commit.com/hooks.html for more hooks
+repos:
+-   repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v5.0.0
+    hooks:
+    -   id: trailing-whitespace
+    -   id: end-of-file-fixer
+    -   id: check-yaml
+    -   id: check-added-large-files
+";
+
+#[allow(clippy::print_stdout)]
+pub(crate) fn sample_config() -> ExitStatus {
+    print!("{SAMPLE_CONFIG}");
+    ExitStatus::Success
+}
diff --git a/src/main.rs b/src/main.rs
index 33acd23..1171fe8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -204,6 +204,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
 
             Ok(cli::validate_manifest(args.manifests))
         }
+        Command::SampleConfig => Ok(cli::sample_config()),
         Command::GenerateShellCompletion(args) => {
             show_settings!(args);
 


Test patch:
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 0ee9792..ce58fef 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -154,6 +154,12 @@ impl TestContext {
         command
     }
 
+    pub fn sample_config(&self) -> Command {
+        let mut command = self.command();
+        command.arg("sample-config");
+        command
+    }
+
     /// Standard snapshot filters _plus_ those for this test context.
     pub fn filters(&self) -> Vec<(&str, &str)> {
         // Put test context snapshots before the default filters
diff --git a/tests/sample_config.rs b/tests/sample_config.rs
new file mode 100644
index 0000000..03baaca
--- /dev/null
+++ b/tests/sample_config.rs
@@ -0,0 +1,27 @@
+use crate::common::{cmd_snapshot, TestContext};
+
+mod common;
+
+#[test]
+fn sample_config() {
+    let context = TestContext::new();
+
+    // Sample configuration.
+    cmd_snapshot!(context.filters(), context.sample_config(), @r##"
+    success: true
+    exit_code: 0
+    ----- stdout -----
+    # See https://pre-commit.com for more information
+    # See https://pre-commit.com/hooks.html for more hooks
+    repos:
+    -   repo: https://github.com/pre-commit/pre-commit-hooks
+        rev: v5.0.0
+        hooks:
+        -   id: trailing-whitespace
+        -   id: end-of-file-fixer
+        -   id: check-yaml
+        -   id: check-added-large-files
+
+    ----- stderr -----
+    "##);
+}