-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add IDs to common objects #592
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ use std::fmt::Formatter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
use std::io::{stdin, stdout, Write}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use std::str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use url::Url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// The `DEL_CONFIRM` is the default value for delete confirmation across different types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub const DEL_CONFIRM: Option<bool> = Some(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -214,6 +215,23 @@ pub fn parse_tag(input: Option<&str>) -> Option<String> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub fn get_uuid_from_url(url: &str) -> String { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if let Ok(url) = Url::parse(url) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let path_segments: Vec<_> = url.path_segments().unwrap().collect(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if let Some(uuid_segment) = path_segments.get(3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if uuid_segment.len() == 36 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
uuid_segment.to_string() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"".to_string() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"".to_string() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"".to_string() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Thanks Adam, good to hear from you! Hope the new gig is going great! I will surely do this. I went down this path at first, but couldn't reconcile the type I was sending into the caller (and Option return type) and got it to the point where "it works" in hopes that the review would shake out the fumbling-my-way-through-it approach! ;) Also, I still feel it's not quite a useful utility function in that it's quite specific to the URL pattern "http:///<api_path>/<api_version>///" where the UUID has to be in the 3 position, but I also don't care to overcomplicate it, so moving the function into the projects file seems prudent, especially since that's all I intended for this "feature"? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Return the default value of a type according to the `Default` trait. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// The type to return is inferred from context; this is equivalent to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a little cleaner to define a constant here like UUID_LENGTH OR UUID_SEGMENT_LENGTH instead of the raw
36
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look!
I've had a chance to think about this a bit too, this is too specific to be in the utils file. If I tried using it for something other than projects it would fail or be inconsistent since we string ids and the ids, for example parameters, could be at another position in the vector.
I think having the parent project's id would be useful, but it may not be worth it unless you or someone else has some advice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you are correct, that's a better way re: constant