diff options
author | notgne2 | 2020-11-27 19:05:55 -0700 |
---|---|---|
committer | notgne2 | 2020-11-27 19:05:55 -0700 |
commit | a19af74789c73601871df4c1fa46d223270d0575 (patch) | |
tree | b599faf9b468a3c394f2bf6a68bb348466bb5231 | |
parent | 26bad3a2a6497997cb694fb7aa0a70822229ec33 (diff) |
Use the last `.` for node/profile name separation, ignore any trailing `.`. This should solve at least part of #10
-rw-r--r-- | src/utils/mod.rs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 2c114f5..4fae7a6 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -49,9 +49,18 @@ pub fn parse_flake(flake: &str) -> DeployFlake { let (node, profile) = match maybe_fragment { Some(fragment) => { - let fragment_profile_start = fragment.find('.'); + let fragment_profile_start = fragment.rfind('.'); + match fragment_profile_start { - Some(s) => (Some(&fragment[..s]), Some(&fragment[s + 1..])), + Some(s) => ( + Some(&fragment[..s]), + // Ignore the trailing `.` + (if (s + 1) == fragment.len() { + None + } else { + Some(&fragment[s + 1..]) + }), + ), None => (Some(fragment), None), } } @@ -93,6 +102,36 @@ fn test_parse_flake() { profile: None, } ); + + // Trailing `.` should be ignored + assert_eq!( + parse_flake("../deploy/examples/system#example."), + DeployFlake { + repo: "../deploy/examples/system", + node: Some("example"), + profile: None + } + ); + + // The last `.` should be used for splitting + assert_eq!( + parse_flake("../deploy/examples/system#example.com.system"), + DeployFlake { + repo: "../deploy/examples/system", + node: Some("example.com"), + profile: Some("system") + } + ); + + // The last `.` should be used for splitting, _and_ trailing `.` should be ignored + assert_eq!( + parse_flake("../deploy/examples/system#example.com."), + DeployFlake { + repo: "../deploy/examples/system", + node: Some("example.com"), + profile: None + } + ); } #[derive(Debug, Clone)] |