-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from nblumhardt/setting-command-group
Add `seqcli setting names|show|set|clear` commands
- Loading branch information
Showing
38 changed files
with
331 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,6 @@ | |
|
||
using Newtonsoft.Json; | ||
|
||
#nullable enable | ||
|
||
namespace SeqCli.Apps.Definitions; | ||
|
||
// ReSharper disable all | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright Datalust Pty Ltd and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using SeqCli.Cli.Features; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.Settings; | ||
|
||
[Command("setting", "clear", "Clear a runtime-configurable server setting")] | ||
class ClearCommand: Command | ||
{ | ||
readonly SeqConnectionFactory _connectionFactory; | ||
|
||
readonly ConnectionFeature _connection; | ||
readonly SettingNameFeature _name; | ||
|
||
public ClearCommand(SeqConnectionFactory connectionFactory) | ||
{ | ||
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
||
_name = Enable<SettingNameFeature>(); | ||
_connection = Enable<ConnectionFeature>(); | ||
} | ||
|
||
protected override async Task<int> Run() | ||
{ | ||
var connection = _connectionFactory.Connect(_connection); | ||
|
||
var setting = await connection.Settings.FindNamedAsync(_name.Name); | ||
setting.Value = null; | ||
await connection.Settings.UpdateAsync(setting); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright Datalust Pty Ltd and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Seq.Api.Model.Settings; | ||
|
||
namespace SeqCli.Cli.Commands.Settings; | ||
|
||
[Command("setting", "names", "Print the names of all supported settings")] | ||
class NamesCommand: Command | ||
{ | ||
protected override Task<int> Run(string[] unrecognized) | ||
{ | ||
foreach (var name in Enum.GetNames(typeof(SettingName)).Order()) | ||
{ | ||
Console.WriteLine(name); | ||
} | ||
|
||
return Task.FromResult(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright Datalust Pty Ltd and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using SeqCli.Cli.Features; | ||
using SeqCli.Connection; | ||
using Serilog; | ||
|
||
namespace SeqCli.Cli.Commands.Settings; | ||
|
||
[Command("setting", "set", "Change a runtime-configurable server setting")] | ||
class SetCommand: Command | ||
{ | ||
readonly SeqConnectionFactory _connectionFactory; | ||
|
||
readonly ConnectionFeature _connection; | ||
readonly SettingNameFeature _name; | ||
|
||
string? _value; | ||
bool _valueSpecified, _readValueFromStdin; | ||
|
||
public SetCommand(SeqConnectionFactory connectionFactory) | ||
{ | ||
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
||
_name = Enable<SettingNameFeature>(); | ||
|
||
Options.Add("v|value=", | ||
"The setting value, comma-separated if multiple values are accepted", | ||
v => | ||
{ | ||
// Not normalized; some settings might include leading/trailing whitespace. | ||
_valueSpecified = true; | ||
_value = v; | ||
}); | ||
|
||
Options.Add("value-stdin", | ||
"Read the value from `STDIN`", | ||
_ => _readValueFromStdin = true); | ||
|
||
_connection = Enable<ConnectionFeature>(); | ||
} | ||
|
||
protected override async Task<int> Run() | ||
{ | ||
if (!_valueSpecified && !_readValueFromStdin) | ||
{ | ||
Log.Error("A value must be supplied with either `--value=VALUE` or `--value-stdin`."); | ||
return 1; | ||
} | ||
|
||
var connection = _connectionFactory.Connect(_connection); | ||
|
||
var setting = await connection.Settings.FindNamedAsync(_name.Name); | ||
setting.Value = ReadValue(); | ||
await connection.Settings.UpdateAsync(setting); | ||
|
||
return 0; | ||
} | ||
|
||
string? ReadValue() | ||
{ | ||
if (_readValueFromStdin) | ||
return Console.In.ReadToEnd().TrimEnd('\r', '\n'); | ||
|
||
return _value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright Datalust Pty Ltd and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Threading.Tasks; | ||
using SeqCli.Cli.Features; | ||
using SeqCli.Connection; | ||
|
||
namespace SeqCli.Cli.Commands.Settings; | ||
|
||
[Command("setting", "show", "Print the current value of a runtime-configurable server setting")] | ||
class ShowCommand: Command | ||
{ | ||
readonly SeqConnectionFactory _connectionFactory; | ||
|
||
readonly ConnectionFeature _connection; | ||
readonly SettingNameFeature _name; | ||
|
||
public ShowCommand(SeqConnectionFactory connectionFactory) | ||
{ | ||
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
||
_name = Enable<SettingNameFeature>(); | ||
_connection = Enable<ConnectionFeature>(); | ||
} | ||
|
||
protected override async Task<int> Run() | ||
{ | ||
var connection = _connectionFactory.Connect(_connection); | ||
|
||
var setting = await connection.Settings.FindNamedAsync(_name.Name); | ||
|
||
if (setting.Value != null) | ||
{ | ||
Console.Write(setting.Value is IFormattable f ? f.ToString(null, CultureInfo.InvariantCulture) : setting.Value.ToString()); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.