@@ -29,7 +29,7 @@ internal class EvaluateCommand : ICommand
2929 public string Namespace => WeaverResources . GlobalNamespace ;
3030
3131 /// <inheritdoc />
32- public int ParameterCount => 1 ;
32+ public int ParameterCount => - 1 ;
3333
3434 /// <inheritdoc />
3535 public CommandSignature Signature => new ( Namespace , Name , ParameterCount ) ;
@@ -58,13 +58,17 @@ public EvaluateCommand(IEvaluator evaluator, IVariableRegistry? registry = null)
5858 /// <inheritdoc />
5959 public CommandResult Execute ( string [ ] args )
6060 {
61- if ( args . Length < 1 )
62- return CommandResult . Fail ( "evaluate() requires at least 1 argument: the expression to evaluate." ) ;
61+ string ? expression = args . Length > 0 ? args [ 0 ] : null ;
62+ string ? targetVar = args . Length > 1 ? args [ 1 ] : null ;
6363
64- var expression = args [ 0 ] ;
65- var targetVar = args . Length > 1 ? args [ 1 ] : null ;
64+ // If no expression, maybe store previous pipeline value or return null
65+ if ( string . IsNullOrWhiteSpace ( expression ) )
66+ {
67+ // Allow empty input if .store() will handle it
68+ return CommandResult . Ok ( null ) ;
69+ }
6670
67- // Resolve variables from registry
71+ // Resolve variables from registry as before
6872 if ( _registry != null )
6973 {
7074 foreach ( var variable in _registry . GetAll ( ) )
@@ -81,7 +85,6 @@ public CommandResult Execute(string[] args)
8185 object ? result ;
8286 EnumTypes type ;
8387
84- // Detect if expression looks like boolean
8588 var isBooleanExpr = _evaluator . IsBooleanExpression ( expression ) ;
8689
8790 try
@@ -105,7 +108,7 @@ public CommandResult Execute(string[] args)
105108 ) ;
106109 }
107110
108- // Optional target variable storage
111+ // Store in registry if requested
109112 if ( ! string . IsNullOrWhiteSpace ( targetVar ) )
110113 {
111114 if ( _registry == null )
@@ -116,15 +119,15 @@ public CommandResult Execute(string[] args)
116119 ) ;
117120 }
118121
119- _registry . Set ( targetVar , result , type ) ;
122+ _registry . Set ( targetVar , result ! , type ) ;
120123 return CommandResult . Ok (
121124 $ "Stored '{ result } ' in '{ targetVar } '.",
122125 result ,
123126 type
124127 ) ;
125128 }
126129
127- // Return result
130+ // Return computed result
128131 var message = type switch
129132 {
130133 EnumTypes . Wbool => result ? . ToString ( ) ?? "false" ,
@@ -141,4 +144,4 @@ public CommandResult InvokeExtension(string extensionName, string[] args)
141144 return CommandResult . Fail ( $ "'{ Name } ' has no extensions.") ;
142145 }
143146 }
144- }
147+ }
0 commit comments