Skip to content

Commit

Permalink
Disable support for shell completion by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Jan 9, 2022
1 parent 536effb commit fb469a1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ or

Currently, The supported shells are `bash` and `zsh`.

This feature is enabled by default, or you can set the `EnableShellCompletionSupport` option to `false` if you don't need it.
This feature is **disabled** by default, or you can set the `EnableShellCompletionSupport` option to `true` if you need it.

It is also possible to dynamically generate command-line completion candidates and to prepare candidates at script generation time. Please see the sample below for more details.

Expand Down
4 changes: 2 additions & 2 deletions src/Cocona.Lite/CoconaLiteAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class CoconaLiteAppOptions
public bool EnableConvertArgumentNameToLowerCase { get; set; } = true;

/// <summary>
/// Specify enable shell completion support. The default value is true.
/// Specify enable shell completion support. The default value is false.
/// </summary>
public bool EnableShellCompletionSupport { get; set; } = true;
public bool EnableShellCompletionSupport { get; set; } = false;
}
}
4 changes: 2 additions & 2 deletions src/Cocona/CoconaAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class CoconaAppOptions
public bool EnableConvertArgumentNameToLowerCase { get; set; } = true;

/// <summary>
/// Specify enable shell completion support. The default value is true.
/// Specify enable shell completion support. The default value is false.
/// </summary>
public bool EnableShellCompletionSupport { get; set; } = true;
public bool EnableShellCompletionSupport { get; set; } = false;
}
}
36 changes: 30 additions & 6 deletions test/Cocona.Test/Integration/CoconaAppRunTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,22 @@ public void CoconaApp_Run_Single_Version(RunBuilderMode mode)
[InlineData(RunBuilderMode.CreateHostBuilder)]
[InlineData(RunBuilderMode.CreateBuilder)]
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Single_Completion(RunBuilderMode mode)
public void CoconaApp_Run_Single_Completion_Disabled_By_Default(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Single>(mode, new string[] { "--completion", "zsh" });

stdErr.Should().Contain("Unknown option 'completion'");
exitCode.Should().Be(129);
}

[Theory]
[InlineData(RunBuilderMode.CreateHostBuilder)]
[InlineData(RunBuilderMode.CreateBuilder)]
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Single_Completion(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Single>(mode, new string[] { "--completion", "zsh" }, options => { options.EnableShellCompletionSupport = true; });

stdOut.Should().Contain("#compdef");
stdErr.Should().BeEmpty();
exitCode.Should().Be(0);
Expand All @@ -76,7 +88,7 @@ public void CoconaApp_Run_Single_Completion(RunBuilderMode mode)
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Single_CompletionCandidates(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Single_Candidates>(mode, new string[] { "--completion-candidates", "bash:name", "--", "A" });
var (stdOut, stdErr, exitCode) = Run<TestCommand_Single_Candidates>(mode, new string[] { "--completion-candidates", "bash:name", "--", "A" }, options => { options.EnableShellCompletionSupport = true; });

stdOut.Should().Contain("Alice");
stdErr.Should().BeEmpty();
Expand Down Expand Up @@ -381,10 +393,22 @@ public void CoconaApp_Run_OptionTest_2(RunBuilderMode mode)
[InlineData(RunBuilderMode.CreateHostBuilder)]
[InlineData(RunBuilderMode.CreateBuilder)]
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Multiple_Completion(RunBuilderMode mode)
public void CoconaApp_Run_Multiple_Completion_Disabled_By_Default(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple>(mode, new string[] { "--completion", "zsh" });

stdErr.Should().Contain("Unknown option 'completion'");
exitCode.Should().Be(129);
}

[Theory]
[InlineData(RunBuilderMode.CreateHostBuilder)]
[InlineData(RunBuilderMode.CreateBuilder)]
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Multiple_Completion(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple>(mode, new string[] { "--completion", "zsh" }, options => { options.EnableShellCompletionSupport = true; });

stdOut.Should().Contain("#compdef");
stdErr.Should().BeEmpty();
exitCode.Should().Be(0);
Expand All @@ -396,7 +420,7 @@ public void CoconaApp_Run_Multiple_Completion(RunBuilderMode mode)
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Multiple_CompletionCandidates(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple_Candidates>(mode, new string[] { "--completion-candidates", "bash:name", "--", "hello", "A" });
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple_Candidates>(mode, new string[] { "--completion-candidates", "bash:name", "--", "hello", "A" }, options => { options.EnableShellCompletionSupport = true; });

stdOut.Should().Contain("Karen");
stdErr.Should().BeEmpty();
Expand All @@ -409,7 +433,7 @@ public void CoconaApp_Run_Multiple_CompletionCandidates(RunBuilderMode mode)
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Multiple_CompletionCandidates_UnknownCommand(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple_Candidates>(mode, new string[] { "--completion-candidates", "bash:name", "--", "unknown-command", "A" });
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple_Candidates>(mode, new string[] { "--completion-candidates", "bash:name", "--", "unknown-command", "A" }, options => { options.EnableShellCompletionSupport = true; });

stdOut.Should().BeEmpty();
stdErr.Should().NotBeEmpty();
Expand All @@ -422,7 +446,7 @@ public void CoconaApp_Run_Multiple_CompletionCandidates_UnknownCommand(RunBuilde
[InlineData(RunBuilderMode.Shortcut)]
public void CoconaApp_Run_Multiple_CompletionCandidates_UnknownOption(RunBuilderMode mode)
{
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple_Candidates>(mode, new string[] { "--completion-candidates", "bash:unknown-option", "--", "hello", "A" });
var (stdOut, stdErr, exitCode) = Run<TestCommand_Multiple_Candidates>(mode, new string[] { "--completion-candidates", "bash:unknown-option", "--", "hello", "A" }, options => { options.EnableShellCompletionSupport = true; });

stdOut.Should().BeEmpty();
stdErr.Should().BeEmpty();
Expand Down

0 comments on commit fb469a1

Please sign in to comment.