-
Notifications
You must be signed in to change notification settings - Fork 36
Accept both simple string and list of strings in args fields for debug config #191
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use regex::Regex; | ||
| use serde::{Deserialize, Serialize, Serializer}; | ||
| use std::{ | ||
| env::current_dir, | ||
| fs, | ||
|
|
@@ -401,3 +402,26 @@ pub fn should_use_local_or_download( | |
| CheckUpdates::Always => Ok(None), | ||
| } | ||
| } | ||
|
|
||
| /// A type that can be deserialized from either a single string or a list of strings. | ||
| /// | ||
| /// When serialized, it always produces a single string. If it was a list, | ||
| /// the elements are joined with a space. | ||
| #[derive(Deserialize, Debug, Clone)] | ||
| #[serde(untagged)] | ||
| pub enum ArgsStringOrList { | ||
| String(String), | ||
| List(Vec<String>), | ||
| } | ||
|
|
||
| impl Serialize for ArgsStringOrList { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: Serializer, | ||
| { | ||
| match self { | ||
| ArgsStringOrList::String(s) => serializer.serialize_str(s), | ||
| ArgsStringOrList::List(l) => serializer.serialize_str(&l.join(" ")), | ||
|
Comment on lines
+423
to
+424
Collaborator
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. Should we consider trimming the string or single elements in the list before joining?
Collaborator
Author
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. Hmm, we could but I don't really see how that gives us anything. Command-line-args are generally separated by "any amount of whitespace" and if users have trailing and/or leading spaces they work just as well. Personally I'd keep the Serializer as stupid as possible so nobody needs to think twice about what it's doing
Collaborator
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. Good, if things are going to work regardless of whitespaces there's not reason not to merge this |
||
| } | ||
| } | ||
| } | ||
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.
Nice touch for adopting the multiple args while maintaining compatibility