Skip to content

Commit f3ebf4a

Browse files
committed
rename targetPath to systemRoot
1 parent 0cd259b commit f3ebf4a

File tree

8 files changed

+27
-29
lines changed

8 files changed

+27
-29
lines changed

dsc/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub enum SubCommand {
4848
parameters: Option<String>,
4949
#[clap(short = 'f', long, help = "Parameters to pass to the configuration as a JSON or YAML file", conflicts_with = "parameters")]
5050
parameters_file: Option<String>,
51-
#[clap(short = 't', long, help = "Target path to apply configuration, requires resource support.")]
52-
target_path: Option<String>,
51+
#[clap(short = 'r', long, help = "Specify the operating system root path if not targeting the current running OS")]
52+
system_root: Option<String>,
5353
// Used to inform when DSC is used as a group resource to modify it's output
5454
#[clap(long, hide = true)]
5555
as_group: bool,

dsc/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ fn main() {
6868
let mut cmd = Args::command();
6969
generate(shell, &mut cmd, "dsc", &mut io::stdout());
7070
},
71-
SubCommand::Config { subcommand, parameters, parameters_file, target_path, as_group, as_include } => {
71+
SubCommand::Config { subcommand, parameters, parameters_file, system_root, as_group, as_include } => {
7272
if let Some(file_name) = parameters_file {
7373
info!("Reading parameters from file {file_name}");
7474
match std::fs::read_to_string(&file_name) {
75-
Ok(parameters) => subcommand::config(&subcommand, &Some(parameters), &target_path, &input, &as_group, &as_include),
75+
Ok(parameters) => subcommand::config(&subcommand, &Some(parameters), &system_root, &input, &as_group, &as_include),
7676
Err(err) => {
7777
error!("Error: Failed to read parameters file '{file_name}': {err}");
7878
exit(util::EXIT_INVALID_INPUT);
7979
}
8080
}
8181
}
8282
else {
83-
subcommand::config(&subcommand, &parameters, &target_path, &input, &as_group, &as_include);
83+
subcommand::config(&subcommand, &parameters, &system_root, &input, &as_group, &as_include);
8484
}
8585
},
8686
SubCommand::Resource { subcommand } => {

dsc/src/subcommand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
279279
exit(EXIT_INVALID_ARGS);
280280
}
281281

282-
configurator.set_target_path(path);
282+
configurator.set_system_root(path);
283283
}
284284

285285
if let Err(err) = configurator.set_context(&parameters) {

dsc/tests/dsc_functions.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Describe 'tests for function expressions' {
2626
}
2727

2828
It 'path(<path>) works' -TestCases @(
29-
@{ path = "targetPath(), 'a'"; expected = "$PSHOME$([System.IO.Path]::DirectorySeparatorChar)a" }
29+
@{ path = "systemRoot(), 'a'"; expected = "$PSHOME$([System.IO.Path]::DirectorySeparatorChar)a" }
3030
@{ path = "'a', 'b', 'c'"; expected = "a$([System.IO.Path]::DirectorySeparatorChar)b$([System.IO.Path]::DirectorySeparatorChar)c" }
3131
) {
3232
param($path, $expected)
@@ -43,14 +43,14 @@ Describe 'tests for function expressions' {
4343
$out.results[0].result.actualState.output | Should -BeExactly $expected
4444
}
4545

46-
It 'default targetPath() is correct for the OS' {
46+
It 'default systemRoot() is correct for the OS' {
4747
$config_yaml = @'
4848
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
4949
resources:
5050
- name: Echo
5151
type: Microsoft.DSC.Debug/Echo
5252
properties:
53-
output: "[targetPath()]"
53+
output: "[systemRoot()]"
5454
'@
5555

5656
$expected = if ($IsWindows) {

dsc_lib/src/configure/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::config_doc::{DataType, SecurityContextKind};
1212
pub struct Context {
1313
pub execution_type: ExecutionKind,
1414
pub outputs: HashMap<String, Value>, // this is used by the `reference()` function to retrieve output
15-
pub target_path: PathBuf,
15+
pub system_root: PathBuf,
1616
pub parameters: HashMap<String, (Value, DataType)>,
1717
pub security_context: SecurityContextKind,
1818
pub variables: HashMap<String, Value>,
@@ -25,7 +25,7 @@ impl Context {
2525
Self {
2626
execution_type: ExecutionKind::Actual,
2727
outputs: HashMap::new(),
28-
target_path: get_default_os_target_path(),
28+
system_root: get_default_os_system_root(),
2929
parameters: HashMap::new(),
3030
security_context: match get_security_context() {
3131
SecurityContext::Admin => SecurityContextKind::Elevated,
@@ -44,13 +44,13 @@ impl Default for Context {
4444
}
4545

4646
#[cfg(target_os = "windows")]
47-
fn get_default_os_target_path() -> PathBuf {
47+
fn get_default_os_system_root() -> PathBuf {
4848
// use SYSTEMDRIVE env var to get the default target path
4949
let system_drive = std::env::var("SYSTEMDRIVE").unwrap_or_else(|_| "C:".to_string());
5050
PathBuf::from(system_drive)
5151
}
5252

5353
#[cfg(not(target_os = "windows"))]
54-
fn get_default_os_target_path() -> PathBuf {
54+
fn get_default_os_system_root() -> PathBuf {
5555
PathBuf::from("/")
5656
}

dsc_lib/src/configure/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ impl Configurator {
485485
/// # Arguments
486486
///
487487
/// * `mounted_path` - The mounted path to set.
488-
pub fn set_target_path(&mut self, target_path: &str) {
489-
self.context.target_path = PathBuf::from(target_path);
488+
pub fn set_system_root(&mut self, system_root: &str) {
489+
self.context.system_root = PathBuf::from(system_root);
490490
}
491491

492492
/// Set the parameters and variables context for the configuration.

dsc_lib/src/functions/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub mod path;
2323
pub mod reference;
2424
pub mod resource_id;
2525
pub mod sub;
26-
pub mod target_path;
26+
pub mod system_root;
2727
pub mod variables;
2828

2929
/// The kind of argument that a function accepts.
@@ -82,7 +82,7 @@ impl FunctionDispatcher {
8282
functions.insert("reference".to_string(), Box::new(reference::Reference{}));
8383
functions.insert("resourceId".to_string(), Box::new(resource_id::ResourceId{}));
8484
functions.insert("sub".to_string(), Box::new(sub::Sub{}));
85-
functions.insert("targetPath".to_string(), Box::new(target_path::TargetPath{}));
85+
functions.insert("systemRoot".to_string(), Box::new(system_root::SystemRoot{}));
8686
functions.insert("variables".to_string(), Box::new(variables::Variables{}));
8787
Self {
8888
functions,

dsc_lib/src/functions/target_path.rs renamed to dsc_lib/src/functions/system_root.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ use serde_json::Value;
88
use tracing::debug;
99

1010
#[derive(Debug, Default)]
11-
pub struct TargetPath {}
11+
pub struct SystemRoot {}
1212

13-
/// Implements the `targetPath` function.
14-
/// This function returns the value of the mounted path.
15-
/// The optional parameter is a path appended to the mounted path.
16-
/// Path is not validated as it might be used for creation.
17-
impl Function for TargetPath {
13+
/// Implements the `systemRoot` function.
14+
/// This function returns the value of the specified system root path.
15+
impl Function for SystemRoot {
1816
fn min_args(&self) -> usize {
1917
0
2018
}
@@ -30,23 +28,23 @@ impl Function for TargetPath {
3028
fn invoke(&self, _args: &[Value], context: &Context) -> Result<Value, DscError> {
3129
debug!("Executing targetPath function");
3230

33-
Ok(Value::String(context.target_path.to_string_lossy().to_string()))
31+
Ok(Value::String(context.system_root.to_string_lossy().to_string()))
3432
}
3533
}
3634

3735
#[cfg(test)]
3836
mod tests {
3937
use crate::configure::context::Context;
4038
use crate::parser::Statement;
41-
use std::{env, path::PathBuf};
39+
use std::path::PathBuf;
4240

4341
#[test]
4442
fn init() {
4543
let mut parser = Statement::new().unwrap();
46-
let result = parser.parse_and_execute("[targetPath()]", &Context::new()).unwrap();
44+
let result = parser.parse_and_execute("[systemRoot()]", &Context::new()).unwrap();
4745
// on windows, the default is SYSTEMDRIVE env var
4846
#[cfg(target_os = "windows")]
49-
assert_eq!(result, env::var("SYSTEMDRIVE").unwrap());
47+
assert_eq!(result, std::env::var("SYSTEMDRIVE").unwrap());
5048
// on linux/macOS, the default is /
5149
#[cfg(not(target_os = "windows"))]
5250
assert_eq!(result, "/");
@@ -57,8 +55,8 @@ mod tests {
5755
let mut parser = Statement::new().unwrap();
5856
let mut context = Context::new();
5957
let separator = std::path::MAIN_SEPARATOR;
60-
context.target_path = PathBuf::from(format!("{separator}mnt"));
61-
let result = parser.parse_and_execute("[targetPath()]", &context).unwrap();
58+
context.system_root = PathBuf::from(format!("{separator}mnt"));
59+
let result = parser.parse_and_execute("[systemRoot()]", &context).unwrap();
6260
assert_eq!(result, format!("{separator}mnt"));
6361
}
6462

0 commit comments

Comments
 (0)