Skip to content
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

Make help be consistent. #1169

Merged
merged 14 commits into from
Sep 7, 2023
Merged

Conversation

BillyONeal
Copy link
Member

@BillyONeal BillyONeal commented Aug 26, 2023

This PR fixes the remaining issues noted in #1164

  • Command synopsis and example information are merged into CommandMetadata
  • This is also used to power autocomplete
    • Note that this fixed a bug: autocomplete thought the command was vcpkg buildexternal but it is vcpkg build-external
  • This is also used to power help
  • The usage text for no arguments is moved into commands.cpp. This is now the one file in the codebase that has to include all the other commands' headers.
  • Pass around MessageT<> where possible rather than needing to make a thunk for everything.

Future work that would be nice I'm not signing up to do:

  • Make autocomplete more aggressive, for example by:
    enum class AutocompleteArguments
    {
        None,
        BuiltinPortNames,
        BuiltinPortNamesAfterPort,
        PortSpecs,
        InstalledPortSpecs,
        Integrate
    };
  • Make autocomplete work on 'frontend' options like --vcpkg-root
  • Make help text not suggest irrelevant 'fontend' options even though they are accepted

Before and after screenshots:

No arguments:

Before and after help with no arguments

help install:

Before and after help install

Autocomplete:

Before and after autocomplete

@BillyONeal BillyONeal added the depends:different-pr This PR depends on a different PR which has been filed label Aug 26, 2023
@autoantwort
Copy link
Contributor

Always funny to learn about new commands even after years :D
The documentation for vcpkg cache is "list names of installed ports", but:

➜  vcpkg git:(cityhash-use-supports) ✗ vcpkg x-set-installed 'boost'                                          
Detecting compiler hash for triplet arm64-osx...
All requested packages are currently installed.
Total install time: 54.2 us
➜  vcpkg git:(cityhash-use-supports) ✗ vcpkg cache                  
No packages are cached.

@BillyONeal
Copy link
Member Author

Always funny to learn about new commands even after years :D
The documentation for vcpkg cache is "list names of installed ports", but:

➜  vcpkg git:(cityhash-use-supports) ✗ vcpkg x-set-installed 'boost'                                          
Detecting compiler hash for triplet arm64-osx...
All requested packages are currently installed.
Total install time: 54.2 us
➜  vcpkg git:(cityhash-use-supports) ✗ vcpkg cache                  
No packages are cached.

I think this thing might just be broken and maybe should be deleted. I'll ask @vicroms if anyone is running this thing....

@BillyONeal
Copy link
Member Author

BillyONeal commented Aug 29, 2023

Review comments on the usage:

  • @ras0219-msft wants to drop "Commands:"
  • @ras0219-msft wants to not need to repeat vcpkg in front of each command
  • The above two mean we need a one line 'breadcrumb' at the top "usage: vcpkg <command> [<args>...]"
  • Either they should all have periods or all not
  • @ras0219-msft wants a vcpkg help commands that lists all commands and remove artifacts commands from vcpkg help.
  • @AugP would like the headers to have the same capitalization. (For more help is lowercase and the others are capitals)
  • @ras0219-msft Would like a new vcpkg help commands that lists the full list like this, and to remove artifacts commands from the 'vcpkg with no arguments' list given that we don't expect to invest in artifacts soon.

@BillyONeal BillyONeal removed the depends:different-pr This PR depends on a different PR which has been filed label Aug 30, 2023
@BillyONeal
Copy link
Member Author

The force push I just pushed should be no changes, just rebasing off the stuff that was identical to #1165

Copy link
Contributor

@ras0219-msft ras0219-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

include/vcpkg/vcpkgcmdarguments.h Show resolved Hide resolved
}

template<class Callback,
std::enable_if_t<std::is_convertible_v<const Callback&, LocalizedString (*)()>, int> = 0>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education: why does this use const Callback& instead of Callback by value?

Copy link
Member Author

@BillyONeal BillyONeal Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are equivalent in this case. I just default to const T& unless I have a specific reason to do otherwise when writing templates.

Note that even if the callback is Callback callback rather than const Callback& callback, the is_convertible_v still needs to have a & since we are converting the callback as an lvalue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also it's smashed to a function pointer at constexpr time so there's no runtime difference; given that all the other ctors take references I'd like to leave this as-is because overload resolution that involves overloads that bind a reference vs. overloads that do not makes my brain hurt...)

}
}

// If no public commands match, try intenral commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If no public commands match, try intenral commands
// If no public commands match, try internal commands

{
"vcpkg env --triplet x64-windows",
msgCommandEnvExample2,
"vcpkg env \"ninja -C build\" --triplet x64-windows",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"vcpkg env \"ninja -C build\" --triplet x64-windows",
"vcpkg env \"ninja --version\" --triplet x64-windows",

A relative path argument to ninja is a bit fraught here since env doesn't retain the outer CWD.

auto msg = msg::format(msgAvailableHelpTopics);
for (auto&& topic_name : all_topic_names)
{
msg.append_raw(fmt::format("\n {}", topic_name));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use LocalizedString::append_indent()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg.append_raw(fmt::format("\n {}", topic_name));
msg.append_raw("\n").append_indent().append_raw(topic_name);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, I'll change it.
  2. GitHub diff fail, I didn't meaningfully change this line from line 177 in the old code.

@@ -86,7 +86,7 @@ namespace

if (switch_.helpmsg)
{
if (cmd_parser.parse_switch(name, tag, parse_result, switch_.helpmsg()) && parse_result)
if (cmd_parser.parse_switch(name, tag, parse_result, switch_.helpmsg.format()) && parse_result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry for not doing the investigation myself)

How does this avoid crashing for switches that have default constructed help (e.g. remove's OPTION_PURGE)?

Copy link
Member Author

@BillyONeal BillyONeal Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if on line 87 will be false because operator bool on that thing returns false if there's nothing inside

}
}

void MetadataMessage::append_to(LocalizedString& target) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void MetadataMessage::append_to(LocalizedString& target) const
void MetadataMessage::format_to(LocalizedString& target) const

(suggestion)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think format_to carries the connotation that the target's contents will be destroyed. How about format_append_to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to to_string since we seem to use that convention elsewhere.

…ndent in all the right places for help. Also remove the "name" which need be localized from the help versioning example now that this is no longer required to avoid needing to localize it.
* drop "Commands:" from @ras0219-msft
* don't repeat `vcpkg ` in front of each command from @ras0219-msft
  * Add 'breadcrumb' for the above
* change all synopsis to not end in periods from @BillyONeal
* split rarely used and artifacts into separate `vcpkg help commands` from @ras0219-msft
* always use Pascal Case headers from @AugP
* make tense for all synopsis and argument help text consistent from @ras0219-msft
* burninate 'instead of' and 'writes out'
template<int N>
/*implicit*/ constexpr LearnWebsiteLinkLiteral(const char (&literal)[N]) noexcept : literal(literal)
{
assert(!constexpr_contains(literal, "en-us") &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some sort of divide-by-zero or array-of-zero thing that can be done here to make this assert compile time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is compile time; assert is constexpr when the assertion passes and not constexpr when the assertion fails.

going and going
shorty
short-arg some really long help text that does not fit on the same line because we
have a 100 character line limit and oh god it keeps going and going
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
have a 100 character line limit and oh god it keeps going and going
have a 100 character line limit and oh no it keeps going and going

void print_full_command_list()
{
HelpTableFormatter table;
format_command_usage_entry(table, CommandAcquireMetadata);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems easy to miss when adding new commands.

Do we have a list of all commands somewhere else we could loop through, skipping based on undocumented, etc?

format_command_usage_entry(table, CommandFetchMetadata);
format_command_usage_entry(table, CommandVersionMetadata);
format_command_usage_entry(table, CommandVsInstancesMetadata);
format_command_usage_entry(table, CommandIntegrateMetadata);
table.blank();

table.header(msg::format(msgForMoreHelp));
table.format("vcpkg help topics", msg::format(msgHelpTopicsCommand));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider dropping vcpkg from these entries.

@BillyONeal BillyONeal merged commit e6c0307 into microsoft:main Sep 7, 2023
5 checks passed
@BillyONeal BillyONeal deleted the merge-help-tables branch September 7, 2023 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants