diff --git a/source/Stargate-API-Skeleton/StargateApplication.class.st b/source/Stargate-API-Skeleton/StargateApplication.class.st index ad7c737..54015b5 100644 --- a/source/Stargate-API-Skeleton/StargateApplication.class.st +++ b/source/Stargate-API-Skeleton/StargateApplication.class.st @@ -155,7 +155,7 @@ StargateApplication >> configureGlobalErrorHandlerIn: api [ yourself ]; on: Exit addErrorHandler: [ :exit | - exit isSuccess then: [ api stop ]. + exit isSuccess then: [ self stop ]. exit pass ] ] @@ -203,6 +203,14 @@ StargateApplication >> logAPIVersion [ LaunchpadLogRecord emitInfo: ( 'API Version: <1s>' expandMacrosWith: self class version ) ] +{ #category : #'private - accessing' } +StargateApplication >> loggersConfiguration [ + + ^ Dictionary new + at: #enabled put: true; + yourself +] + { #category : #'private - accessing' } StargateApplication >> metricsConfiguration [ @@ -226,6 +234,7 @@ StargateApplication >> operationsConfiguration [ at: ApplicationInfoPlugin endpoint put: self applicationInfoConfiguration; at: ApplicationConfigurationPlugin endpoint put: self applicationConfigurationConfiguration; at: ApplicationControlPlugin endpoint put: self applicationControlConfiguration; + at: LoggersPlugin endpoint put: self loggersConfiguration; yourself ] diff --git a/source/Stargate-Application-Control-Tests/ApplicationControlCommandTest.class.st b/source/Stargate-Application-Control-Tests/ApplicationControlCommandTest.class.st index 1619b8d..e6d1434 100644 --- a/source/Stargate-Application-Control-Tests/ApplicationControlCommandTest.class.st +++ b/source/Stargate-Application-Control-Tests/ApplicationControlCommandTest.class.st @@ -16,5 +16,34 @@ ApplicationControlCommandTest >> testAccessing [ self assert: command methodName equals: 'shutdown'; - assert: command parameterCount equals: 0 + assert: command parameterCount equals: 0; + assert: command parameterNames isEmpty +] + +{ #category : #tests } +ApplicationControlCommandTest >> testCannotCreateUnnamed [ + + self should: [ ApplicationControlCommand named: '' executing: [ self fail ] ] + raise: InstanceCreationFailed + withMessageText: 'Cannot create an unnamed command' +] + +{ #category : #tests } +ApplicationControlCommandTest >> testCannotCreateWhenArgumentCountIsMismatched [ + + self + should: [ ApplicationControlCommand named: 'echo' executing: [ :message | self fail ] ] + raise: InstanceCreationFailed + withMessageText: 'The number of parameter names doesn''t match the block arity'; + should: [ + ApplicationControlCommand named: 'echo' withArgumentNames: #( message ) executing: [ self fail ] ] + raise: InstanceCreationFailed + withMessageText: 'The number of parameter names doesn''t match the block arity'; + should: [ + ApplicationControlCommand named: 'echo' + withArgumentNames: #( message async ) + executing: [ :message | self fail ] + ] + raise: InstanceCreationFailed withMessageText: + 'The number of parameter names doesn''t match the block arity' ] diff --git a/source/Stargate-Application-Control-Tests/ApplicationControlPluginAPITest.class.st b/source/Stargate-Application-Control-Tests/ApplicationControlPluginAPITest.class.st index 6156c0d..1505220 100644 --- a/source/Stargate-Application-Control-Tests/ApplicationControlPluginAPITest.class.st +++ b/source/Stargate-Application-Control-Tests/ApplicationControlPluginAPITest.class.st @@ -42,8 +42,9 @@ ApplicationControlPluginAPITest >> requiredPermissions [ { #category : #running } ApplicationControlPluginAPITest >> setUp [ - ApplicationControlPlugin - registerAsAvailableCommand: ( ApplicationControlCommand named: 'echo' executing: [ :message | message ] ). + ApplicationControlPlugin registerAsAvailableCommand: ( ApplicationControlCommand named: 'echo' + withArgumentNames: #( message ) + executing: [ :message | message ] ). super setUp ] diff --git a/source/Stargate-Application-Control/ApplicationControlCommand.class.st b/source/Stargate-Application-Control/ApplicationControlCommand.class.st index 3258285..6112d45 100644 --- a/source/Stargate-Application-Control/ApplicationControlCommand.class.st +++ b/source/Stargate-Application-Control/ApplicationControlCommand.class.st @@ -7,7 +7,8 @@ Class { #superclass : #Object, #instVars : [ 'methodName', - 'actionBlock' + 'actionBlock', + 'parameterNames' ], #category : #'Stargate-Application-Control' } @@ -15,24 +16,39 @@ Class { { #category : #'instance creation' } ApplicationControlCommand class >> named: aMethodName executing: aBlockClosure [ - AssertionChecker - enforce: [ aMethodName notEmpty ] - because: 'Cannot create an unnamed command' - raising: InstanceCreationFailed. + ^ self named: aMethodName withArgumentNames: #( ) executing: aBlockClosure +] + +{ #category : #'instance creation' } +ApplicationControlCommand class >> named: aMethodName withArgumentNames: argumentNames executing: aBlockClosure [ + + AssertionCheckerBuilder new + raising: InstanceCreationFailed; + checking: [ :asserter | + asserter + enforce: [ aMethodName notEmpty ] because: 'Cannot create an unnamed command'; + enforce: [ argumentNames size = aBlockClosure argumentCount ] + because: 'The number of parameter names doesn''t match the block arity' + ]; + buildAndCheck. + - ^ self new initializeNamed: aMethodName executing: aBlockClosure + ^ self new initializeNamed: aMethodName withArgumentNames: argumentNames executing: aBlockClosure ] { #category : #configuring } ApplicationControlCommand >> addTo: aJsonRPCRequestHandler [ - aJsonRPCRequestHandler addHandlerNamed: methodName evaluating: actionBlock + aJsonRPCRequestHandler addHandlerNamed: methodName + withArgumentNames: parameterNames + evaluating: actionBlock ] { #category : #initialization } -ApplicationControlCommand >> initializeNamed: aMethodName executing: aBlockClosure [ +ApplicationControlCommand >> initializeNamed: aMethodName withArgumentNames: theArgumentNames executing: aBlockClosure [ methodName := aMethodName. + parameterNames := theArgumentNames. actionBlock := aBlockClosure ] @@ -45,5 +61,11 @@ ApplicationControlCommand >> methodName [ { #category : #accessing } ApplicationControlCommand >> parameterCount [ - ^ actionBlock argumentCount + ^ parameterNames size +] + +{ #category : #accessing } +ApplicationControlCommand >> parameterNames [ + + ^ parameterNames ]