-
Notifications
You must be signed in to change notification settings - Fork 38
Add --system-root
parameter, systemRoot()
and path()
functions to dsc
#589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
15e04f7
Add `--mounted-path` parameter to dsc
ab7d491
change to `--target-path` and `targetPath()`. add `path()` function
SteveL-MSFT 8195405
fix tests
SteveL-MSFT ddbe82f
update test
SteveL-MSFT b2a5528
update test
SteveL-MSFT 7fd5060
Update dsc_lib/src/functions/target_path.rs
SteveL-MSFT c099c9e
fix description of path function
SteveL-MSFT 405794a
fix clippy
SteveL-MSFT 71350a0
fix default for targetPath if not specified
SteveL-MSFT fe5f098
fix windows default to not including trailing backslash
SteveL-MSFT 0cd259b
fix unit test
SteveL-MSFT f3ebf4a
rename targetPath to systemRoot
SteveL-MSFT ca2d441
fix test
SteveL-MSFT 677b5ec
fix test
SteveL-MSFT 3e3d473
Merge branch 'main' into mounted-path
SteveL-MSFT 5e1ffb3
Update dsc_lib/src/configure/mod.rs
SteveL-MSFT 6be82a1
Merge branch 'main' into mounted-path
SteveL-MSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use crate::DscError; | ||
use crate::configure::context::Context; | ||
use crate::functions::{AcceptedArgKind, Function}; | ||
use serde_json::Value; | ||
use std::path::PathBuf; | ||
use tracing::debug; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct Path {} | ||
|
||
/// Implements the 'mountedpath' function. | ||
/// This function returns the value of the mounted path. | ||
/// The optional parameter is a path appended to the mounted path. | ||
/// Path is not validated as it might be used for creation. | ||
impl Function for Path { | ||
fn min_args(&self) -> usize { | ||
2 | ||
} | ||
|
||
fn max_args(&self) -> usize { | ||
usize::MAX | ||
} | ||
|
||
fn accepted_arg_types(&self) -> Vec<AcceptedArgKind> { | ||
vec![AcceptedArgKind::String] | ||
} | ||
|
||
fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> { | ||
debug!("Executing path function with args: {:?}", args); | ||
|
||
let mut path = PathBuf::new(); | ||
for arg in args { | ||
if let Value::String(s) = arg { | ||
path.push(s); | ||
} else { | ||
return Err(DscError::Parser("Arguments must all be strings".to_string())); | ||
} | ||
} | ||
|
||
Ok(Value::String(path.to_string_lossy().to_string())) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::configure::context::Context; | ||
use crate::parser::Statement; | ||
|
||
#[test] | ||
fn two_args() { | ||
let mut parser = Statement::new().unwrap(); | ||
let separator = std::path::MAIN_SEPARATOR; | ||
let result = parser.parse_and_execute("[path('a','b')]", &Context::new()).unwrap(); | ||
assert_eq!(result, format!("a{separator}b")); | ||
} | ||
|
||
#[test] | ||
fn three_args() { | ||
let mut parser = Statement::new().unwrap(); | ||
let separator = std::path::MAIN_SEPARATOR; | ||
let result = parser.parse_and_execute("[path('a','b','c')]", &Context::new()).unwrap(); | ||
assert_eq!(result, format!("a{separator}b{separator}c")); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use crate::DscError; | ||
use crate::configure::context::Context; | ||
use crate::functions::{AcceptedArgKind, Function}; | ||
use serde_json::Value; | ||
use tracing::debug; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct TargetPath {} | ||
|
||
/// Implements the 'mountedpath' function. | ||
SteveL-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// This function returns the value of the mounted path. | ||
/// The optional parameter is a path appended to the mounted path. | ||
/// Path is not validated as it might be used for creation. | ||
impl Function for TargetPath { | ||
fn min_args(&self) -> usize { | ||
0 | ||
} | ||
|
||
fn max_args(&self) -> usize { | ||
0 | ||
} | ||
|
||
fn accepted_arg_types(&self) -> Vec<AcceptedArgKind> { | ||
vec![AcceptedArgKind::String] | ||
} | ||
|
||
fn invoke(&self, _args: &[Value], context: &Context) -> Result<Value, DscError> { | ||
debug!("Executing targetPath function"); | ||
|
||
Ok(Value::String(context.target_path.to_string_lossy().to_string())) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::configure::context::Context; | ||
use crate::parser::Statement; | ||
use std::path::PathBuf; | ||
|
||
#[test] | ||
fn init() { | ||
let mut parser = Statement::new().unwrap(); | ||
let result = parser.parse_and_execute("[targetPath()]", &Context::new()).unwrap(); | ||
assert_eq!(result, ""); | ||
} | ||
|
||
#[test] | ||
fn simple() { | ||
let mut parser = Statement::new().unwrap(); | ||
let mut context = Context::new(); | ||
let separator = std::path::MAIN_SEPARATOR; | ||
context.target_path = PathBuf::from(format!("{separator}mnt")); | ||
let result = parser.parse_and_execute("[targetPath()]", &context).unwrap(); | ||
assert_eq!(result, format!("{separator}mnt")); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.