Skip to content

Commit 3f01a63

Browse files
authored
Merge pull request #4 from stackabletech/review
Implement feedback from #1
2 parents 2bcd1cf + d764c4e commit 3f01a63

14 files changed

+130
-79
lines changed

.github/workflows/build.yml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# =============
2+
# This file is copied (and adopted) from the templates in stackabletech/operator-templating
3+
# =============
4+
---
5+
name: Stackable Build Pipeline
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
- staging
12+
- trying
13+
- "renovate/**"
14+
pull_request:
15+
merge_group:
16+
17+
env:
18+
CARGO_TERM_COLOR: always
19+
CARGO_INCREMENTAL: '0'
20+
CARGO_PROFILE_DEV_DEBUG: '0'
21+
RUST_TOOLCHAIN_VERSION: "1.78.0"
22+
RUSTFLAGS: "-D warnings"
23+
RUSTDOCFLAGS: "-D warnings"
24+
RUST_LOG: "info"
25+
DEV_REPO_HELM_URL: https://repo.stackable.tech/repository/helm-dev
26+
TEST_REPO_HELM_URL: https://repo.stackable.tech/repository/helm-test
27+
STABLE_REPO_HELM_URL: https://repo.stackable.tech/repository/helm-stable
28+
29+
jobs:
30+
run_rustfmt:
31+
name: Run Rustfmt
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
35+
with:
36+
submodules: recursive
37+
- uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a
38+
with:
39+
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
40+
components: rustfmt
41+
- run: cargo fmt --all -- --check
42+
43+
run_clippy:
44+
name: Run Clippy
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
48+
with:
49+
submodules: recursive
50+
- uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a
51+
with:
52+
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
53+
components: clippy
54+
- name: Run clippy action to produce annotations
55+
uses: giraffate/clippy-action@13b9d32482f25d29ead141b79e7e04e7900281e0 # v1.0.1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
if: env.GITHUB_TOKEN != null
59+
with:
60+
clippy_flags: --all-targets -- -D warnings
61+
reporter: 'github-pr-review'
62+
github_token: ${{ secrets.GITHUB_TOKEN }}
63+
- name: Run clippy manually without annotations
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
if: env.GITHUB_TOKEN == null
67+
run: cargo clippy --color never -q --all-targets -- -D warnings
68+
69+
run_rustdoc:
70+
name: Run RustDoc
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
74+
with:
75+
submodules: recursive
76+
- uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a
77+
with:
78+
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
79+
components: rustfmt
80+
- run: cargo doc --document-private-items
81+
82+
run_tests:
83+
name: Run Cargo Tests
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
87+
with:
88+
submodules: recursive
89+
- uses: dtolnay/rust-toolchain@d8352f6b1d2e870bc5716e7a6d9b65c4cc244a1a
90+
with:
91+
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
92+
- run: cargo test

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
# The following files are mentioned as an example in the README, so let's exclude them
44
example.xml
55
example-password
6+
7+
tests/resources/properties/*.properties
8+
tests/resources/xml/*.xml

src/cli_args.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::path::PathBuf;
2-
31
use clap::{Parser, Subcommand};
42

5-
use config_utils::file_types::FileType;
3+
use config_utils::template::cli_args::TemplateCommand;
64

75
/// Utility that helps you handling config files.
86
#[derive(Debug, Parser)]
@@ -14,20 +12,5 @@ pub struct Args {
1412

1513
#[derive(Debug, Subcommand)]
1614
pub enum Command {
17-
/// Fill out variables in config files from either env variables or files directly.
18-
Template {
19-
/// The path to the file that should be templated
20-
file: PathBuf,
21-
22-
/// The optional file type of the file to be templated. If this is not specified this utility will try to infer
23-
/// the type based on the file name.
24-
#[arg(value_enum)]
25-
file_type: Option<FileType>,
26-
27-
/// By default inserted values are automatically escaped according to the deteced file format. You can disable
28-
/// this, e.g. when you need to insert XML tags (as they otherwise would be escaped).
29-
/// NOTE: Please make sure to correctly escape the inserted text on your own!
30-
#[clap(long)]
31-
dont_escape: bool,
32-
},
15+
Template(TemplateCommand),
3316
}

src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::Parser;
2-
use config_utils::template::{self, template};
2+
use config_utils::template::{self, cli_args::TemplateCommand, template};
33
use snafu::{ResultExt, Snafu};
44

55
use cli_args::{Args, Command};
@@ -19,11 +19,11 @@ fn main() -> Result<()> {
1919
let args = Args::parse();
2020

2121
match args.command {
22-
Command::Template {
22+
Command::Template(TemplateCommand {
2323
file,
2424
file_type,
2525
dont_escape,
26-
} => {
26+
}) => {
2727
template(&file, file_type.as_ref(), !dont_escape).context(TemplateFileSnafu)?;
2828
}
2929
}

src/template/cli_args.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::path::PathBuf;
2+
3+
use clap::Parser;
4+
5+
use crate::file_types::FileType;
6+
7+
/// Fill out variables in config files from either env variables or files directly.
8+
#[derive(Debug, Parser)]
9+
pub struct TemplateCommand {
10+
/// The path to the file that should be templated
11+
pub file: PathBuf,
12+
13+
/// The optional file type of the file to be templated. If this is not specified this utility will try to infer
14+
/// the type based on the file name.
15+
#[arg(value_enum)]
16+
pub file_type: Option<FileType>,
17+
18+
/// By default inserted values are automatically escaped according to the deteced file format. You can disable
19+
/// this, e.g. when you need to insert XML tags (as they otherwise would be escaped).
20+
/// NOTE: Please make sure to correctly escape the inserted text on your own!
21+
#[clap(long)]
22+
pub dont_escape: bool,
23+
}

src/template.rs renamed to src/template/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use crate::{
1212
ENV_VAR_PATTERN_END, ENV_VAR_PATTERN_START, FILE_PATTERN_END, FILE_PATTERN_START,
1313
};
1414

15+
pub mod cli_args;
16+
1517
#[derive(Debug, Snafu)]
1618
pub enum Error {
1719
#[snafu(display("Could not read file {file_name:?}"))]
@@ -125,7 +127,7 @@ pub fn template(file_name: &PathBuf, file_type: Option<&FileType>, escape: bool)
125127
})?;
126128
}
127129

128-
fs::rename(&tmp_file_name, &file_name).context(RenameTemporaryFileSnafu {
130+
fs::rename(&tmp_file_name, file_name).context(RenameTemporaryFileSnafu {
129131
tmp_file_name,
130132
destination_file_name: file_name,
131133
})?;

tests/resources/properties/security_from_env.properties

-4
This file was deleted.

tests/resources/properties/security_from_file.properties

-3
This file was deleted.

tests/resources/properties/security_from_file.properties.expected

-3
This file was deleted.

tests/resources/properties/security_from_file.properties.in

-3
This file was deleted.

tests/resources/properties/security_from_nested.properties

-4
This file was deleted.

tests/resources/properties/security_untouched.properties

-3
This file was deleted.

tests/resources/xml/nifi_ldap.xml

-32
This file was deleted.

tests/templating.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{
22
env,
33
fs::{self, File},
44
io::Write,
5-
path::PathBuf,
5+
path::{Path, PathBuf},
66
};
77

88
use rstest::rstest;
@@ -21,13 +21,13 @@ fn test_file_templating(#[files("tests/resources/**/*.in")] test_file_in: PathBu
2121
fs::copy(&test_file_in, &test_file).unwrap();
2222
template(&test_file, None, true).unwrap();
2323

24-
let actual = fs::read_to_string(&test_file).unwrap();
25-
let expected = fs::read_to_string(&test_file_expected).unwrap();
24+
let actual = fs::read_to_string(test_file).unwrap();
25+
let expected = fs::read_to_string(test_file_expected).unwrap();
2626

2727
similar_asserts::assert_eq!(actual, expected);
2828
}
2929

30-
fn set_example_envs(example_dir: &PathBuf) {
30+
fn set_example_envs(example_dir: &Path) {
3131
// SAFETY: We only use a single thread to set this env vars
3232
env::set_var("ENV_TEST", "foo");
3333
env::set_var("ENV_TEST_USERNAME", "example user");

0 commit comments

Comments
 (0)