@@ -8,19 +8,57 @@ namespace AIShell.Integration.Commands;
8
8
[ Cmdlet ( VerbsLifecycle . Invoke , "AIShell" , DefaultParameterSetName = "Default" ) ]
9
9
public class InvokeAIShellCommand : PSCmdlet
10
10
{
11
- [ Parameter ( Mandatory = true , ValueFromRemainingArguments = true ) ]
11
+ private const string DefaultSet = "Default" ;
12
+ private const string ClipboardSet = "Clipboard" ;
13
+ private const string PostCodeSet = "PostCode" ;
14
+ private const string CopyCodeSet = "CopyCode" ;
15
+ private const string ExitSet = "Exit" ;
16
+
17
+ /// <summary>
18
+ /// Sets and gets the query to be sent to AIShell
19
+ /// </summary>
20
+ [ Parameter ( Mandatory = true , ValueFromRemainingArguments = true , ParameterSetName = DefaultSet ) ]
21
+ [ Parameter ( Mandatory = true , ValueFromRemainingArguments = true , ParameterSetName = ClipboardSet ) ]
12
22
public string [ ] Query { get ; set ; }
13
23
14
- [ Parameter ]
24
+ /// <summary>
25
+ /// Sets and gets the agent to use for the query.
26
+ /// </summary>
27
+ [ Parameter ( ParameterSetName = DefaultSet ) ]
28
+ [ Parameter ( ParameterSetName = ClipboardSet ) ]
15
29
[ ValidateNotNullOrEmpty ]
16
30
public string Agent { get ; set ; }
17
31
18
- [ Parameter ( ParameterSetName = "Default" , Mandatory = false , ValueFromPipeline = true ) ]
32
+ /// <summary>
33
+ /// Sets and gets the context information for the query.
34
+ /// </summary>
35
+ [ Parameter ( ValueFromPipeline = true , ParameterSetName = DefaultSet ) ]
19
36
public PSObject Context { get ; set ; }
20
37
21
- [ Parameter ( ParameterSetName = "Clipboard" , Mandatory = true ) ]
38
+ /// <summary>
39
+ /// Indicates getting context information from clipboard.
40
+ /// </summary>
41
+ [ Parameter ( Mandatory = true , ParameterSetName = ClipboardSet ) ]
22
42
public SwitchParameter ContextFromClipboard { get ; set ; }
23
43
44
+ /// <summary>
45
+ /// Indicates running '/code post' from the AIShell.
46
+ /// </summary>
47
+ [ Parameter ( ParameterSetName = PostCodeSet ) ]
48
+ public SwitchParameter PostCode { get ; set ; }
49
+
50
+ /// <summary>
51
+ /// Indicates running '/code copy' from the AIShell.
52
+ /// </summary>
53
+ [ Parameter ( ParameterSetName = CopyCodeSet ) ]
54
+ public SwitchParameter CopyCode { get ; set ; }
55
+
56
+ /// <summary>
57
+ /// Indicates running '/exit' from the AIShell.
58
+ /// </summary>
59
+ [ Parameter ( ParameterSetName = ExitSet ) ]
60
+ public SwitchParameter Exit { get ; set ; }
61
+
24
62
private List < PSObject > _contextObjects ;
25
63
26
64
protected override void ProcessRecord ( )
@@ -36,25 +74,43 @@ protected override void ProcessRecord()
36
74
37
75
protected override void EndProcessing ( )
38
76
{
39
- Collection < string > results = null ;
40
- if ( _contextObjects is not null )
41
- {
42
- using PowerShell pwsh = PowerShell . Create ( RunspaceMode . CurrentRunspace ) ;
43
- results = pwsh
44
- . AddCommand ( "Out-String" )
45
- . AddParameter ( "InputObject" , _contextObjects )
46
- . Invoke < string > ( ) ;
47
- }
48
- else if ( ContextFromClipboard )
77
+ string message , context = null ;
78
+
79
+ switch ( ParameterSetName )
49
80
{
50
- using PowerShell pwsh = PowerShell . Create ( RunspaceMode . CurrentRunspace ) ;
51
- results = pwsh
52
- . AddCommand ( "Get-Clipboard" )
53
- . AddParameter ( "Raw" )
54
- . Invoke < string > ( ) ;
81
+ case PostCodeSet :
82
+ message = "/code post" ;
83
+ break ;
84
+ case CopyCodeSet :
85
+ message = "/code copy" ;
86
+ break ;
87
+ case ExitSet :
88
+ message = "/exit" ;
89
+ break ;
90
+ default :
91
+ Collection < string > results = null ;
92
+ if ( _contextObjects is not null )
93
+ {
94
+ using PowerShell pwsh = PowerShell . Create ( RunspaceMode . CurrentRunspace ) ;
95
+ results = pwsh
96
+ . AddCommand ( "Out-String" )
97
+ . AddParameter ( "InputObject" , _contextObjects )
98
+ . Invoke < string > ( ) ;
99
+ }
100
+ else if ( ContextFromClipboard )
101
+ {
102
+ using PowerShell pwsh = PowerShell . Create ( RunspaceMode . CurrentRunspace ) ;
103
+ results = pwsh
104
+ . AddCommand ( "Get-Clipboard" )
105
+ . AddParameter ( "Raw" )
106
+ . Invoke < string > ( ) ;
107
+ }
108
+
109
+ context = results ? . Count > 0 ? results [ 0 ] : null ;
110
+ message = string . Join ( ' ' , Query ) ;
111
+ break ;
55
112
}
56
113
57
- string context = results ? . Count > 0 ? results [ 0 ] : null ;
58
- Channel . Singleton . PostQuery ( new PostQueryMessage ( string . Join ( ' ' , Query ) , context , Agent ) ) ;
114
+ Channel . Singleton . PostQuery ( new PostQueryMessage ( message , context , Agent ) ) ;
59
115
}
60
116
}
0 commit comments