1+ // Copyright © Datalust Pty Ltd and Contributors
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ using System ;
16+ using System . IO ;
17+ using System . Threading . Tasks ;
18+ using SeqCli . Cli . Features ;
19+ using SeqCli . Config ;
20+ using Serilog ;
21+
22+ // ReSharper disable once UnusedType.Global
23+
24+ namespace SeqCli . Cli . Commands . Config ;
25+
26+ [ Command ( "config" , "set" , "Set a field in the `SeqCli.json` file" ) ]
27+ class SetCommand : Command
28+ {
29+ readonly StoragePathFeature _storagePath ;
30+ readonly ConfigKeyFeature _key ;
31+ readonly ConfigValueFeature _value ;
32+
33+ public SetCommand ( )
34+ {
35+ _storagePath = Enable < StoragePathFeature > ( ) ;
36+ _key = Enable < ConfigKeyFeature > ( ) ;
37+ _value = Enable < ConfigValueFeature > ( ) ;
38+ }
39+
40+ protected override Task < int > Run ( )
41+ {
42+ var config = SeqCliConfig . ReadFromFile ( _storagePath . ConfigFilePath ) ;
43+
44+ KeyValueSettings . Set ( config , _key . GetKey ( ) , _value . ReadValue ( ) ) ;
45+ SeqCliConfig . WriteToFile ( config , _storagePath . ConfigFilePath ) ;
46+ return Task . FromResult ( 0 ) ;
47+ }
48+ }
0 commit comments