1414
1515using System ;
1616using System . Threading . Tasks ;
17+ using Seq . Api . Model . Signals ;
1718using SeqCli . Cli . Features ;
1819using SeqCli . Config ;
1920using SeqCli . Connection ;
21+ using SeqCli . Signals ;
2022using SeqCli . Syntax ;
2123using SeqCli . Util ;
2224using Serilog ;
@@ -33,7 +35,8 @@ class CreateCommand : Command
3335 readonly OutputFormatFeature _output ;
3436
3537 string ? _afterDuration ;
36- bool _deleteAllEvents ; // Currently the only supported option
38+ bool _deleteAllEvents ;
39+ string ? _deleteMatchingSignal ;
3740
3841 public CreateCommand ( SeqConnectionFactory connectionFactory , SeqCliConfig config )
3942 {
@@ -48,6 +51,15 @@ public CreateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config
4851 "delete-all-events" ,
4952 "The policy should delete all events (currently the only supported option)" ,
5053 _ => _deleteAllEvents = true ) ;
54+
55+ Options . Add (
56+ "delete=" ,
57+ "Stream incoming events to this app instance as they're ingested; optionally accepts a signal expression limiting which events should be streamed" ,
58+ s =>
59+ {
60+ _deleteMatchingSignal = s ;
61+ }
62+ ) ;
5163
5264 _connection = Enable < ConnectionFeature > ( ) ;
5365 _output = Enable ( new OutputFormatFeature ( config . Output ) ) ;
@@ -57,12 +69,29 @@ protected override async Task<int> Run()
5769 {
5870 var connection = _connectionFactory . Connect ( _connection ) ;
5971
60- if ( ! _deleteAllEvents )
72+ SignalExpressionPart ? removedSignalExpression ;
73+
74+ // Exactly one of `delete-all-events` or `delete` must be specified
75+ if ( _deleteAllEvents )
76+ {
77+ if ( ! string . IsNullOrEmpty ( _deleteMatchingSignal ) )
78+ {
79+ Log . Error ( "Only one of the `delete-all-events` or `delete` options may be specified" ) ;
80+ return 1 ;
81+ }
82+
83+ removedSignalExpression = null ;
84+ }
85+ else if ( string . IsNullOrEmpty ( _deleteMatchingSignal ) )
6186 {
62- Log . Error ( "The `delete-all-events` option must be specified" ) ;
87+ Log . Error ( "Either the `delete-all-events` or `delete` options must be specified" ) ;
6388 return 1 ;
6489 }
65-
90+ else
91+ {
92+ removedSignalExpression = SignalExpressionParser . ParseExpression ( _deleteMatchingSignal ! ) ;
93+ }
94+
6695 if ( _afterDuration == null )
6796 {
6897 Log . Error ( "A duration must be specified using `after`" ) ;
@@ -73,6 +102,7 @@ protected override async Task<int> Run()
73102
74103 var policy = await connection . RetentionPolicies . TemplateAsync ( ) ;
75104 policy . RetentionTime = duration ;
105+ policy . RemovedSignalExpression = removedSignalExpression ;
76106
77107 policy = await connection . RetentionPolicies . AddAsync ( policy ) ;
78108
0 commit comments