diff --git a/dsc/src/util.rs b/dsc/src/util.rs index dd6c9e44f..84014f215 100644 --- a/dsc/src/util.rs +++ b/dsc/src/util.rs @@ -367,11 +367,17 @@ pub fn parse_input_to_json(value: &str) -> String { pub fn get_input(input: &Option, stdin: &Option, path: &Option) -> String { let value = match (input, stdin, path) { (Some(_), Some(_), None) | (None, Some(_), Some(_)) => { - error!("Error: Cannot specify both stdin and --input or --path"); + error!("Error: Cannot specify both stdin and --document or --path"); exit(EXIT_INVALID_ARGS); }, (Some(input), None, None) => { debug!("Reading input from command line parameter"); + + // see if user accidentally passed in a file path + if Path::new(input).exists() { + error!("Error: Document provided is a file path, use --path instead"); + exit(EXIT_INVALID_INPUT); + } input.clone() }, (None, Some(stdin), None) => { @@ -413,7 +419,7 @@ pub fn get_input(input: &Option, stdin: &Option, path: &Option String exit(EXIT_DSC_ERROR); }; - let Some(config_root_path) = full_path.parent() else { + let Some(config_root_path) = full_path.parent() else { // this should never happen because path was absolutized error!("Error reading config path parent"); exit(EXIT_DSC_ERROR); }; let env_var = "DSC_CONFIG_ROOT"; - + // warn if env var is already set/used if env::var(env_var).is_ok() { warn!("The current value of '{env_var}' env var will be overridden"); diff --git a/dsc/tests/dsc_args.tests.ps1 b/dsc/tests/dsc_args.tests.ps1 index 2917a0e67..2b4de7bb3 100644 --- a/dsc/tests/dsc_args.tests.ps1 +++ b/dsc/tests/dsc_args.tests.ps1 @@ -271,4 +271,10 @@ resources: $r.requireAdapter.StartsWith("Test") | Should -Be $true $r.kind | Should -Be "Resource" } + + It 'passing filepath to document arg should error' { + $configFile = Resolve-Path $PSScriptRoot/../examples/osinfo.dsc.json + $stderr = dsc config get -d $configFile 2>&1 + $stderr | Should -Match '.*?--path.*?' + } }