jborean93 / pypsrp

PowerShell Remoting Protocol for Python
MIT License
328 stars 49 forks source link

Add convenience options to 'add_cmdlet' and 'add_script' #134

Closed malthe closed 2 years ago

codecov[bot] commented 2 years ago

Codecov Report

Merging #134 (268b373) into master (c86765b) will decrease coverage by 0.05%. The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #134      +/-   ##
==========================================
- Coverage   99.66%   99.60%   -0.06%     
==========================================
  Files          13       13              
  Lines        3297     3303       +6     
==========================================
+ Hits         3286     3290       +4     
- Misses         11       13       +2     
Flag Coverage Δ
py3.10 99.60% <75.00%> (-0.06%) :arrow_down:
py3.6 99.60% <75.00%> (-0.06%) :arrow_down:
py3.7 99.60% <75.00%> (-0.06%) :arrow_down:
py3.8 99.57% <75.00%> (-0.06%) :arrow_down:
py3.9 99.57% <75.00%> (-0.06%) :arrow_down:
ubuntu 98.33% <75.00%> (-0.06%) :arrow_down:
windows 99.60% <75.00%> (-0.07%) :arrow_down:
x64 99.60% <75.00%> (-0.06%) :arrow_down:
x86 99.60% <75.00%> (-0.07%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pypsrp/powershell.py 99.71% <75.00%> (-0.29%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c86765b...268b373. Read the comment docs.

malthe commented 2 years ago

@jborean93 not sure this is really a good idea. My use-case is that I wanted users to be able to easily have an "init script" such as:

> Set-PSDebug -Trace 1

And it seemed a little awkward with the composable interface.

jborean93 commented 2 years ago

I'm unsure how I feel about this one. The current setup is designed to replicate the PowerShell class to the best it can. The add_cmdlet is already a convenience operation as you can't normally do overloading in a simple way that AddCommand offers and the latter is reserved for when adding an actual Command instance rather than just the string. This is certainly easier to do compared to before but even so I'm not 100% convinced before was even that hard to begin with.

ps = PowerShell(rp)
ps.add_cmdlet('My-Function').add_parameters({...}).add_statement()

# vs

ps.add_cmdlet('My-Function', parameters={...}, end_of_statement=True)

In fact end_of_statement makes it longer than the original so you don't really save on typing there. I'm happy to be convinced otherwise but I'm somewhat leaning towards just keep it the same as the .NET API.

malthe commented 2 years ago

I suppose I could instead prepare a "canned" command, which could easily be imported and added to the pipeline.

debug = Command("Set-PSDebug", args=CommandParameter("Trace", 1), end_of_statement=True)

I'll go ahead and close out this pull request.