wt.exe
: Add support for "short" sub-commands (#6576)
This adds `nt`, `sp`, and `ft` as aliases for `new-tab`, `split-pane`, and `focus-tab`, respectively. These do exactly the same thing as their long for counterparts, but are just shorter, for those of us who type slower than a fifth grader 👀 Now you can do ``` wt nt cmd.exe /k #work 15 ; sp cmd.exe /k #work 15 ; sp cmd.exe /k media-commandline ; nt powershell dev\\symbols.ps1 ; nt -p \"Ubuntu\" ; nt -p \"Ubuntu\" ; ft -t 0 ``` instead of ``` new-tab cmd.exe /k #work 15 ; split-pane cmd.exe /k #work 15 ; split-pane cmd.exe /k media-commandline ; new-tab powershell dev\\symbols.ps1 ; new-tab -p \"Ubuntu\" ; new-tab -p \"Ubuntu\" ; focus-tab -t 0 ``` The pattern I'm using here is that each of these subcommands now has a little helper lambda that actually sets up the subcommand with the required arguments, and we just call that lambda twice, once for the long-form of the command, and again for the short. I imagine that in the future, we won't necessarily have short-forms for every subcommands, so if there are future conflicts we'd have to figure that out pre-emptively, but these all seem like they'll need a short form. Closes #5466
This commit is contained in:
parent
54a7fce3e0
commit
445da4bae4
|
@ -388,9 +388,16 @@ namespace TerminalAppLocalTests
|
|||
|
||||
void CommandlineTest::ParseNewTabCommand()
|
||||
{
|
||||
BEGIN_TEST_METHOD_PROPERTIES()
|
||||
TEST_METHOD_PROPERTY(L"Data:useShortForm", L"{false, true}")
|
||||
END_TEST_METHOD_PROPERTIES()
|
||||
|
||||
INIT_TEST_PROPERTY(bool, useShortForm, L"If true, use `nt` instead of `new-tab`");
|
||||
const wchar_t* subcommand = useShortForm ? L"nt" : L"new-tab";
|
||||
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -409,7 +416,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"--profile", L"cmd" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"--profile", L"cmd" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -429,7 +436,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"--startingDirectory", L"c:\\Foo" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"--startingDirectory", L"c:\\Foo" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -449,7 +456,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"powershell.exe" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"powershell.exe" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -469,7 +476,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"powershell.exe", L"This is an arg with spaces" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"powershell.exe", L"This is an arg with spaces" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -490,7 +497,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"powershell.exe", L"This is an arg with spaces", L"another-arg", L"more spaces in this one" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"powershell.exe", L"This is an arg with spaces", L"another-arg", L"more spaces in this one" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -511,7 +518,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"-p", L"Windows PowerShell" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-p", L"Windows PowerShell" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -531,7 +538,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"wsl", L"-d", L"Alpine" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"wsl", L"-d", L"Alpine" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -551,7 +558,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L"-p", L"1", L"wsl", L"-d", L"Alpine" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-p", L"1", L"wsl", L"-d", L"Alpine" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -574,9 +581,16 @@ namespace TerminalAppLocalTests
|
|||
|
||||
void CommandlineTest::ParseSplitPaneIntoArgs()
|
||||
{
|
||||
BEGIN_TEST_METHOD_PROPERTIES()
|
||||
TEST_METHOD_PROPERTY(L"Data:useShortForm", L"{false, true}")
|
||||
END_TEST_METHOD_PROPERTIES()
|
||||
|
||||
INIT_TEST_PROPERTY(bool, useShortForm, L"If true, use `sp` instead of `split-pane`");
|
||||
const wchar_t* subcommand = useShortForm ? L"sp" : L"split-pane";
|
||||
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"split-pane" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(2u, appArgs._startupActions.size());
|
||||
|
@ -595,7 +609,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"split-pane", L"-H" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-H" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(2u, appArgs._startupActions.size());
|
||||
|
@ -614,7 +628,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"split-pane", L"-V" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-V" };
|
||||
auto commandlines = AppCommandlineArgs::BuildCommands(rawCommands);
|
||||
VERIFY_ARE_EQUAL(1u, commandlines.size());
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
@ -635,7 +649,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"split-pane", L"-p", L"1", L"wsl", L"-d", L"Alpine" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-p", L"1", L"wsl", L"-d", L"Alpine" };
|
||||
auto commandlines = AppCommandlineArgs::BuildCommands(rawCommands);
|
||||
VERIFY_ARE_EQUAL(1u, commandlines.size());
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
@ -662,7 +676,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"split-pane", L"-p", L"1", L"-H", L"wsl", L"-d", L"Alpine" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-p", L"1", L"-H", L"wsl", L"-d", L"Alpine" };
|
||||
auto commandlines = AppCommandlineArgs::BuildCommands(rawCommands);
|
||||
VERIFY_ARE_EQUAL(1u, commandlines.size());
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
@ -689,7 +703,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"split-pane", L"-p", L"1", L"wsl", L"-d", L"Alpine", L"-H" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-p", L"1", L"wsl", L"-d", L"Alpine", L"-H" };
|
||||
auto commandlines = AppCommandlineArgs::BuildCommands(rawCommands);
|
||||
VERIFY_ARE_EQUAL(1u, commandlines.size());
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
@ -718,8 +732,18 @@ namespace TerminalAppLocalTests
|
|||
|
||||
void CommandlineTest::ParseComboCommandlineIntoArgs()
|
||||
{
|
||||
BEGIN_TEST_METHOD_PROPERTIES()
|
||||
TEST_METHOD_PROPERTY(L"Data:useShortFormNewTab", L"{false, true}")
|
||||
TEST_METHOD_PROPERTY(L"Data:useShortFormSplitPane", L"{false, true}")
|
||||
END_TEST_METHOD_PROPERTIES()
|
||||
|
||||
INIT_TEST_PROPERTY(bool, useShortFormNewTab, L"If true, use `nt` instead of `new-tab`");
|
||||
INIT_TEST_PROPERTY(bool, useShortFormSplitPane, L"If true, use `sp` instead of `split-pane`");
|
||||
const wchar_t* ntSubcommand = useShortFormNewTab ? L"nt" : L"new-tab";
|
||||
const wchar_t* spSubcommand = useShortFormSplitPane ? L"sp" : L"split-pane";
|
||||
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"new-tab", L";", L"split-pane" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", ntSubcommand, L";", spSubcommand };
|
||||
auto commandlines = AppCommandlineArgs::BuildCommands(rawCommands);
|
||||
_buildCommandlinesHelper(appArgs, 2u, rawCommands);
|
||||
|
||||
|
@ -834,9 +858,16 @@ namespace TerminalAppLocalTests
|
|||
|
||||
void CommandlineTest::ParseFocusTabArgs()
|
||||
{
|
||||
BEGIN_TEST_METHOD_PROPERTIES()
|
||||
TEST_METHOD_PROPERTY(L"Data:useShortForm", L"{false, true}")
|
||||
END_TEST_METHOD_PROPERTIES()
|
||||
|
||||
INIT_TEST_PROPERTY(bool, useShortForm, L"If true, use `ft` instead of `focus-tab`");
|
||||
const wchar_t* subcommand = useShortForm ? L"ft" : L"focus-tab";
|
||||
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"focus-tab" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
@ -846,7 +877,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"focus-tab", L"-n" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-n" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(2u, appArgs._startupActions.size());
|
||||
|
@ -860,7 +891,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"focus-tab", L"-p" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-p" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(2u, appArgs._startupActions.size());
|
||||
|
@ -874,7 +905,7 @@ namespace TerminalAppLocalTests
|
|||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"focus-tab", L"-t", L"2" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-t", L"2" };
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(2u, appArgs._startupActions.size());
|
||||
|
@ -894,7 +925,7 @@ namespace TerminalAppLocalTests
|
|||
Log::Comment(NoThrowString().Format(
|
||||
L"Attempt an invalid combination of flags"));
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", L"focus-tab", L"-p", L"-n" };
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"-p", L"-n" };
|
||||
|
||||
auto commandlines = AppCommandlineArgs::BuildCommands(rawCommands);
|
||||
VERIFY_ARE_EQUAL(1u, commandlines.size());
|
||||
|
|
|
@ -195,6 +195,7 @@ void AppCommandlineArgs::_buildParser()
|
|||
|
||||
// Method Description:
|
||||
// - Adds the `new-tab` subcommand and related options to the commandline parser.
|
||||
// - Additionally adds the `nt` subcommand, which is just a shortened version of `new-tab`
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
|
@ -202,27 +203,35 @@ void AppCommandlineArgs::_buildParser()
|
|||
void AppCommandlineArgs::_buildNewTabParser()
|
||||
{
|
||||
_newTabCommand.subcommand = _app.add_subcommand("new-tab", RS_A(L"CmdNewTabDesc"));
|
||||
_addNewTerminalArgs(_newTabCommand);
|
||||
_newTabShort.subcommand = _app.add_subcommand("nt", RS_A(L"CmdNTDesc"));
|
||||
|
||||
// When ParseCommand is called, if this subcommand was provided, this
|
||||
// callback function will be triggered on the same thread. We can be sure
|
||||
// that `this` will still be safe - this function just lets us know this
|
||||
// command was parsed.
|
||||
_newTabCommand.subcommand->callback([&, this]() {
|
||||
// Build the NewTab action from the values we've parsed on the commandline.
|
||||
auto newTabAction = winrt::make_self<implementation::ActionAndArgs>();
|
||||
newTabAction->Action(ShortcutAction::NewTab);
|
||||
auto args = winrt::make_self<implementation::NewTabArgs>();
|
||||
// _getNewTerminalArgs MUST be called before parsing any other options,
|
||||
// as it might clear those options while finding the commandline
|
||||
args->TerminalArgs(_getNewTerminalArgs(_newTabCommand));
|
||||
newTabAction->Args(*args);
|
||||
_startupActions.push_back(*newTabAction);
|
||||
});
|
||||
auto setupSubcommand = [this](auto& subcommand) {
|
||||
_addNewTerminalArgs(subcommand);
|
||||
|
||||
// When ParseCommand is called, if this subcommand was provided, this
|
||||
// callback function will be triggered on the same thread. We can be sure
|
||||
// that `this` will still be safe - this function just lets us know this
|
||||
// command was parsed.
|
||||
subcommand.subcommand->callback([&, this]() {
|
||||
// Build the NewTab action from the values we've parsed on the commandline.
|
||||
auto newTabAction = winrt::make_self<implementation::ActionAndArgs>();
|
||||
newTabAction->Action(ShortcutAction::NewTab);
|
||||
auto args = winrt::make_self<implementation::NewTabArgs>();
|
||||
// _getNewTerminalArgs MUST be called before parsing any other options,
|
||||
// as it might clear those options while finding the commandline
|
||||
args->TerminalArgs(_getNewTerminalArgs(subcommand));
|
||||
newTabAction->Args(*args);
|
||||
_startupActions.push_back(*newTabAction);
|
||||
});
|
||||
};
|
||||
|
||||
setupSubcommand(_newTabCommand);
|
||||
setupSubcommand(_newTabShort);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Adds the `split-pane` subcommand and related options to the commandline parser.
|
||||
// - Additionally adds the `sp` subcommand, which is just a shortened version of `split-pane`
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
|
@ -230,49 +239,57 @@ void AppCommandlineArgs::_buildNewTabParser()
|
|||
void AppCommandlineArgs::_buildSplitPaneParser()
|
||||
{
|
||||
_newPaneCommand.subcommand = _app.add_subcommand("split-pane", RS_A(L"CmdSplitPaneDesc"));
|
||||
_addNewTerminalArgs(_newPaneCommand);
|
||||
_horizontalOption = _newPaneCommand.subcommand->add_flag("-H,--horizontal",
|
||||
_splitHorizontal,
|
||||
RS_A(L"CmdSplitPaneHorizontalArgDesc"));
|
||||
_verticalOption = _newPaneCommand.subcommand->add_flag("-V,--vertical",
|
||||
_splitVertical,
|
||||
RS_A(L"CmdSplitPaneVerticalArgDesc"));
|
||||
_verticalOption->excludes(_horizontalOption);
|
||||
_newPaneShort.subcommand = _app.add_subcommand("sp", RS_A(L"CmdSPDesc"));
|
||||
|
||||
// When ParseCommand is called, if this subcommand was provided, this
|
||||
// callback function will be triggered on the same thread. We can be sure
|
||||
// that `this` will still be safe - this function just lets us know this
|
||||
// command was parsed.
|
||||
_newPaneCommand.subcommand->callback([&, this]() {
|
||||
// Build the SplitPane action from the values we've parsed on the commandline.
|
||||
auto splitPaneActionAndArgs = winrt::make_self<implementation::ActionAndArgs>();
|
||||
splitPaneActionAndArgs->Action(ShortcutAction::SplitPane);
|
||||
auto args = winrt::make_self<implementation::SplitPaneArgs>();
|
||||
// _getNewTerminalArgs MUST be called before parsing any other options,
|
||||
// as it might clear those options while finding the commandline
|
||||
args->TerminalArgs(_getNewTerminalArgs(_newPaneCommand));
|
||||
args->SplitStyle(SplitState::Automatic);
|
||||
// Make sure to use the `Option`s here to check if they were set -
|
||||
// _getNewTerminalArgs might reset them while parsing a commandline
|
||||
if ((*_horizontalOption || *_verticalOption))
|
||||
{
|
||||
if (_splitHorizontal)
|
||||
{
|
||||
args->SplitStyle(SplitState::Horizontal);
|
||||
}
|
||||
else if (_splitVertical)
|
||||
{
|
||||
args->SplitStyle(SplitState::Vertical);
|
||||
}
|
||||
}
|
||||
auto setupSubcommand = [this](auto& subcommand) {
|
||||
_addNewTerminalArgs(subcommand);
|
||||
subcommand._horizontalOption = subcommand.subcommand->add_flag("-H,--horizontal",
|
||||
_splitHorizontal,
|
||||
RS_A(L"CmdSplitPaneHorizontalArgDesc"));
|
||||
subcommand._verticalOption = subcommand.subcommand->add_flag("-V,--vertical",
|
||||
_splitVertical,
|
||||
RS_A(L"CmdSplitPaneVerticalArgDesc"));
|
||||
subcommand._verticalOption->excludes(subcommand._horizontalOption);
|
||||
|
||||
splitPaneActionAndArgs->Args(*args);
|
||||
_startupActions.push_back(*splitPaneActionAndArgs);
|
||||
});
|
||||
// When ParseCommand is called, if this subcommand was provided, this
|
||||
// callback function will be triggered on the same thread. We can be sure
|
||||
// that `this` will still be safe - this function just lets us know this
|
||||
// command was parsed.
|
||||
subcommand.subcommand->callback([&, this]() {
|
||||
// Build the SplitPane action from the values we've parsed on the commandline.
|
||||
auto splitPaneActionAndArgs = winrt::make_self<implementation::ActionAndArgs>();
|
||||
splitPaneActionAndArgs->Action(ShortcutAction::SplitPane);
|
||||
auto args = winrt::make_self<implementation::SplitPaneArgs>();
|
||||
// _getNewTerminalArgs MUST be called before parsing any other options,
|
||||
// as it might clear those options while finding the commandline
|
||||
args->TerminalArgs(_getNewTerminalArgs(subcommand));
|
||||
args->SplitStyle(SplitState::Automatic);
|
||||
// Make sure to use the `Option`s here to check if they were set -
|
||||
// _getNewTerminalArgs might reset them while parsing a commandline
|
||||
if ((*subcommand._horizontalOption || *subcommand._verticalOption))
|
||||
{
|
||||
if (_splitHorizontal)
|
||||
{
|
||||
args->SplitStyle(SplitState::Horizontal);
|
||||
}
|
||||
else if (_splitVertical)
|
||||
{
|
||||
args->SplitStyle(SplitState::Vertical);
|
||||
}
|
||||
}
|
||||
|
||||
splitPaneActionAndArgs->Args(*args);
|
||||
_startupActions.push_back(*splitPaneActionAndArgs);
|
||||
});
|
||||
};
|
||||
|
||||
setupSubcommand(_newPaneCommand);
|
||||
setupSubcommand(_newPaneShort);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Adds the `new-tab` subcommand and related options to the commandline parser.
|
||||
// - Adds the `focus-tab` subcommand and related options to the commandline parser.
|
||||
// - Additionally adds the `ft` subcommand, which is just a shortened version of `focus-tab`
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
|
@ -280,39 +297,48 @@ void AppCommandlineArgs::_buildSplitPaneParser()
|
|||
void AppCommandlineArgs::_buildFocusTabParser()
|
||||
{
|
||||
_focusTabCommand = _app.add_subcommand("focus-tab", RS_A(L"CmdFocusTabDesc"));
|
||||
auto* indexOpt = _focusTabCommand->add_option("-t,--target", _focusTabIndex, RS_A(L"CmdFocusTabTargetArgDesc"));
|
||||
auto* nextOpt = _focusTabCommand->add_flag("-n,--next",
|
||||
_focusNextTab,
|
||||
RS_A(L"CmdFocusTabNextArgDesc"));
|
||||
auto* prevOpt = _focusTabCommand->add_flag("-p,--previous",
|
||||
_focusPrevTab,
|
||||
RS_A(L"CmdFocusTabPrevArgDesc"));
|
||||
nextOpt->excludes(prevOpt);
|
||||
indexOpt->excludes(prevOpt);
|
||||
indexOpt->excludes(nextOpt);
|
||||
_focusTabShort = _app.add_subcommand("ft", RS_A(L"CmdFTDesc"));
|
||||
|
||||
// When ParseCommand is called, if this subcommand was provided, this
|
||||
// callback function will be triggered on the same thread. We can be sure
|
||||
// that `this` will still be safe - this function just lets us know this
|
||||
// command was parsed.
|
||||
_focusTabCommand->callback([&, this]() {
|
||||
// Build the action from the values we've parsed on the commandline.
|
||||
auto focusTabAction = winrt::make_self<implementation::ActionAndArgs>();
|
||||
auto setupSubcommand = [this](auto* subcommand) {
|
||||
auto* indexOpt = subcommand->add_option("-t,--target",
|
||||
_focusTabIndex,
|
||||
RS_A(L"CmdFocusTabTargetArgDesc"));
|
||||
auto* nextOpt = subcommand->add_flag("-n,--next",
|
||||
_focusNextTab,
|
||||
RS_A(L"CmdFocusTabNextArgDesc"));
|
||||
auto* prevOpt = subcommand->add_flag("-p,--previous",
|
||||
_focusPrevTab,
|
||||
RS_A(L"CmdFocusTabPrevArgDesc"));
|
||||
nextOpt->excludes(prevOpt);
|
||||
indexOpt->excludes(prevOpt);
|
||||
indexOpt->excludes(nextOpt);
|
||||
|
||||
if (_focusTabIndex >= 0)
|
||||
{
|
||||
focusTabAction->Action(ShortcutAction::SwitchToTab);
|
||||
auto args = winrt::make_self<implementation::SwitchToTabArgs>();
|
||||
args->TabIndex(_focusTabIndex);
|
||||
focusTabAction->Args(*args);
|
||||
_startupActions.push_back(*focusTabAction);
|
||||
}
|
||||
else if (_focusNextTab || _focusPrevTab)
|
||||
{
|
||||
focusTabAction->Action(_focusNextTab ? ShortcutAction::NextTab : ShortcutAction::PrevTab);
|
||||
_startupActions.push_back(*focusTabAction);
|
||||
}
|
||||
});
|
||||
// When ParseCommand is called, if this subcommand was provided, this
|
||||
// callback function will be triggered on the same thread. We can be sure
|
||||
// that `this` will still be safe - this function just lets us know this
|
||||
// command was parsed.
|
||||
subcommand->callback([&, this]() {
|
||||
// Build the action from the values we've parsed on the commandline.
|
||||
auto focusTabAction = winrt::make_self<implementation::ActionAndArgs>();
|
||||
|
||||
if (_focusTabIndex >= 0)
|
||||
{
|
||||
focusTabAction->Action(ShortcutAction::SwitchToTab);
|
||||
auto args = winrt::make_self<implementation::SwitchToTabArgs>();
|
||||
args->TabIndex(_focusTabIndex);
|
||||
focusTabAction->Args(*args);
|
||||
_startupActions.push_back(*focusTabAction);
|
||||
}
|
||||
else if (_focusNextTab || _focusPrevTab)
|
||||
{
|
||||
focusTabAction->Action(_focusNextTab ? ShortcutAction::NextTab : ShortcutAction::PrevTab);
|
||||
_startupActions.push_back(*focusTabAction);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
setupSubcommand(_focusTabCommand);
|
||||
setupSubcommand(_focusTabShort);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
|
@ -409,7 +435,10 @@ NewTerminalArgs AppCommandlineArgs::_getNewTerminalArgs(AppCommandlineArgs::NewT
|
|||
bool AppCommandlineArgs::_noCommandsProvided()
|
||||
{
|
||||
return !(*_newTabCommand.subcommand ||
|
||||
*_newTabShort.subcommand ||
|
||||
*_focusTabCommand ||
|
||||
*_focusTabShort ||
|
||||
*_newPaneShort.subcommand ||
|
||||
*_newPaneCommand.subcommand);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,15 +56,21 @@ private:
|
|||
CLI::Option* titleOption;
|
||||
};
|
||||
|
||||
struct NewPaneSubcommand : public NewTerminalSubcommand
|
||||
{
|
||||
CLI::Option* _horizontalOption;
|
||||
CLI::Option* _verticalOption;
|
||||
};
|
||||
|
||||
// --- Subcommands ---
|
||||
NewTerminalSubcommand _newTabCommand;
|
||||
NewTerminalSubcommand _newPaneCommand;
|
||||
NewTerminalSubcommand _newTabShort;
|
||||
NewPaneSubcommand _newPaneCommand;
|
||||
NewPaneSubcommand _newPaneShort;
|
||||
CLI::App* _focusTabCommand;
|
||||
CLI::App* _focusTabShort;
|
||||
// Are you adding a new sub-command? Make sure to update _noCommandsProvided!
|
||||
|
||||
CLI::Option* _horizontalOption;
|
||||
CLI::Option* _verticalOption;
|
||||
|
||||
std::string _profileName;
|
||||
std::string _startingDirectory;
|
||||
std::string _startingTitle;
|
||||
|
|
|
@ -231,6 +231,10 @@
|
|||
<data name="CmdFocusTabNextArgDesc" xml:space="preserve">
|
||||
<value>Move focus to the next tab</value>
|
||||
</data>
|
||||
<data name="CmdFTDesc" xml:space="preserve">
|
||||
<value>An alias for the "focus-tab" subcommand.</value>
|
||||
<comment>{Locked="\"focus-tab\""}</comment>
|
||||
</data>
|
||||
<data name="CmdFocusTabPrevArgDesc" xml:space="preserve">
|
||||
<value>Move focus to the previous tab</value>
|
||||
</data>
|
||||
|
@ -240,12 +244,20 @@
|
|||
<data name="CmdNewTabDesc" xml:space="preserve">
|
||||
<value>Create a new tab</value>
|
||||
</data>
|
||||
<data name="CmdNTDesc" xml:space="preserve">
|
||||
<value>An alias for the "new-tab" subcommand.</value>
|
||||
<comment>{Locked="\"new-tab\""}</comment>
|
||||
</data>
|
||||
<data name="CmdProfileArgDesc" xml:space="preserve">
|
||||
<value>Open with the given profile. Accepts either the name or GUID of a profile</value>
|
||||
</data>
|
||||
<data name="CmdSplitPaneDesc" xml:space="preserve">
|
||||
<value>Create a new split pane</value>
|
||||
</data>
|
||||
<data name="CmdSPDesc" xml:space="preserve">
|
||||
<value>An alias for the "split-pane" subcommand.</value>
|
||||
<comment>{Locked="\"split-pane\""}</comment>
|
||||
</data>
|
||||
<data name="CmdSplitPaneHorizontalArgDesc" xml:space="preserve">
|
||||
<value>Create the new pane as a horizontal split (think [-])</value>
|
||||
</data>
|
||||
|
|
Loading…
Reference in a new issue