Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for -ArgumentList on Routes, Handlers, Timers, Schedules, etc #330

Closed
Badgerati opened this issue Aug 10, 2019 · 2 comments · Fixed by #333
Closed

Allow for -ArgumentList on Routes, Handlers, Timers, Schedules, etc #330

Badgerati opened this issue Aug 10, 2019 · 2 comments · Fixed by #333

Comments

@Badgerati
Copy link
Owner

This will contain a fair few changes, the main one is being able to supply an -ArgumentList on Routes, Schedules, Handlers, Timers, and possibly others (maybe Middleware and Authentication).

All:

  • The event and supplied arguments should be splatted, so they can be like:
param($event, $arg1, $arg2, ...)

Schedules:

  • Because they are invoked as a Runspace, the argument names are literal.
  • The current, and only argument, is $Lockable. This should be changed to be within an $Event hashtable.
  • Because parameter names are literal, the -ArgumentList for Schedules will be a hashtable rather than an array
Add-PodeSchedule -Name 'Example' -Cron '@minutely' -ScriptBlock {
    param($event, $key, $path)
    # logic
} -ArgumentList @{ Key = 'SomeValue'; Path = 'SomePath' }

Timers, Routes, and others:

  • Allow for -ArgumentList array to be supplied
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
    param($e, $arg1, $opt2, $username)
    # logic
} -ArgumentList $SomeArgument, $SomeOption, $SomeUsername

Handlers:

  • TCP handlers are correct - just need the -ArgumentList.
  • SMTP handlers supply the wrong event. It should be $e.Email and $e.Lockable - but only the $email is supplied.
  • Server handlers get no event at all, so that needs adding.
@Badgerati Badgerati added this to the 1.0.0 milestone Aug 10, 2019
@Badgerati Badgerati added this to To do in Function Syntax Refactor via automation Aug 10, 2019
Badgerati added a commit that referenced this issue Aug 11, 2019
@Badgerati Badgerati self-assigned this Aug 12, 2019
@LLIT
Copy link

LLIT commented Aug 13, 2019

Is this an alternative to Get-Podestate?
How about "Global" arguments, just like you have with the middleware?

@Badgerati
Copy link
Owner Author

Get-PodeState is more for creating and sharing variables between the different runspaces. This is like Invoke-Command, where you'll be able to set certain args that are always supplied to route scriptblocks for the route you set them against.

So arguments for specific routes/middleware/timers, etc., like the -Options on custom middleware/logging/authentication but -ArgumentList is replacing that for something more familiar.

It'll also allow more dynamic building of routes - as something I was going to look into was a ConvertTo-PodeRoute -Commands Get-ChildItem, Remove-Item or ConvertTo-PodeRoute -Module Azure, and Pode will dynamically build routes for the (public) functions for you (with the original function being supplied to a route in its -ArgumentList.

Ie:

Add-PodeRoute -Method Get -Path '/ChildItem' -ScriptBlock {
    param($e, $function)
    . $function
} -ArgumentList 'Get-ChildItem'

@Badgerati Badgerati moved this from To do to In progress in Function Syntax Refactor Aug 13, 2019
Function Syntax Refactor automation moved this from In progress to Done Aug 14, 2019
Badgerati added a commit that referenced this issue Aug 14, 2019
#330: Add ArgumentList Parameter to most Functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants