-
Notifications
You must be signed in to change notification settings - Fork 189
added partial support for -p flags in lsbom #207
base: master
Are you sure you want to change the base?
Conversation
Libraries/libbom/Tools/lsbom.cpp
Outdated
* Username | ||
* UserGroupName | ||
*/ | ||
std::string |
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.
nit: static std::string
Libraries/libbom/Tools/lsbom.cpp
Outdated
* UserGroupName | ||
*/ | ||
std::string | ||
printItemToString(Options::PrintItem item, std::string path, struct bom_path_info_2 *info){ |
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.
nit: PrintItemToString
(or StringFromPrintItem
)
nit: {
on a new line
Libraries/libbom/Tools/lsbom.cpp
Outdated
*/ | ||
std::string | ||
printItemToString(Options::PrintItem item, std::string path, struct bom_path_info_2 *info){ | ||
|
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.
nit: remove empty line
Libraries/libbom/Tools/lsbom.cpp
Outdated
return std::to_string(ntohl(info->group)); | ||
case Options::PrintItem::GroupName: | ||
|
||
break; |
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.
For these unfinished ones, I'd do it like this:
case Options::PrintItem::SomeCase:
return std::string(); // TODO: implement
Libraries/libbom/Tools/lsbom.cpp
Outdated
break; | ||
} | ||
|
||
return ""; |
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.
(Once the unimplemented ones have return
above, can remove this.)
Libraries/libbom/Tools/lsbom.cpp
Outdated
@@ -451,6 +513,18 @@ main(int argc, char **argv) | |||
*/ | |||
if (options->onlyPath()) { | |||
printf("%s\n", path.c_str()); | |||
} else if (options->printFormat()) { | |||
|
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.
nit: remove empty line
Libraries/libbom/Tools/lsbom.cpp
Outdated
std::string toPrint; | ||
|
||
for (Options::PrintItem item : *options->printFormat()) { | ||
toPrint += first? "" : "\t"; |
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.
nit: space before ?
79a1a39
to
d10956e
Compare
d10956e
to
4cd9560
Compare
Libraries/libbom/Tools/lsbom.cpp
Outdated
toReturn.push_back(Options::PrintItem::FileSize); | ||
toReturn.push_back(Options::PrintItem::Checksum); | ||
|
||
return toReturn; |
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.
This could use an "initializer list" to create the vector:
std::vector<Options::PrintItem> toReturn = {
Options::PrintItem::FileName,
Options::PrintItem::Permissions,
Options::PrintItem::UserGroupID,
Options::PrintItem::FileSize,
Options::PrintItem::Checksum,
};
return toReturn;
Or even remove the temporary variable completely:
return {
Options::PrintItem::FileName,
Options::PrintItem::Permissions,
Options::PrintItem::UserGroupID,
Options::PrintItem::FileSize,
Options::PrintItem::Checksum,
};
I like that style better for two reasons. Most importantly, I think it's easier to read: the structure of the code matches the structure of the data structure created. And not important in this case, but it's also slightly faster since it avoids calling push_back
five times, each of which might need to expand the vector's allocated space.
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.
The initialiser list looks like a slightly faster, cleaner way to do this.
I'll make that change, thanks!
Libraries/libbom/Tools/lsbom.cpp
Outdated
} | ||
|
||
printf("\n"); | ||
toPrint = PrintItemsToString(GetDefaultPrintFormat(), path, path_info_2_value); |
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.
Rather than the else if
and else
, here, you could do this:
} else {
std::vector<Options::PrintItem> printFormat = options->printFormat().value_or(GetDefaultPrintFormat());
toPrint = PrintItemsToString(printFormat, path, path_info_2_value);
}
Using the built-in value_or
function to use a default if no printFormat
is specified in the options
.
Beyond that, you could even remove the if
entirely:
std::vector<Options::PrintItem> printFormat = options->printFormat().value_or(
options->onlyPath() ? { Options::PrintItem::FileName } : GetDefaultPrintFormat());
toPrint = PrintItemsToString(printFormat, path, path_info_2_value);
Then, you could remove the PrintItemsToString
function and just put the code right in here, since it's only called once.
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.
I notice that in your value_or solution, if printFormat has been filled in via the -p flag, then onlyPath no longer takes precedence over the -p flag as lsbom.
Perhaps you meant:
std::vector<Options::PrintItem> printFormat = options->onlyPath() ? std::vector<Options::PrintItem>({Options::PrintItem::FileName}) : options->printFormat().value_or(GetDefaultPrintFormat());
And this too looks good!
I'll get this in there, and thanks again for the feedback!
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.
Good catch, sounds best to ignore the second half of my comment!
Libraries/libbom/Tools/lsbom.cpp
Outdated
} | ||
|
||
static std::vector<Options::PrintItem> | ||
GetDefaultPrintFormat () |
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.
nit: no space before ()
4cd9560
to
2f239d8
Compare
2f239d8
to
caf7ede
Compare
refactored code for printing lsbom details
caf7ede
to
17d96d9
Compare
Tried pulling a fresh copy from the current main version, and noticed at lsbom doesn't seem to work anymore as I get "error: failed to load paths tree." Tried tracing it to see what went wrong and here's what I got so far:
|
Thanks! |
No description provided.