Skip to content

Commit

Permalink
Handle multiple exits by detecting session changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlm committed Jun 28, 2018
1 parent 8502804 commit 311478c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Clap-Core/ClapCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ClapCommand >> matchClass [
ClapCommand >> runWith: arguments [
"Convenience method for running a command in an interactive context"
^ (ClapContext with: self)
interpret: arguments
activateWith: arguments
]

{ #category : #accessing }
Expand Down
39 changes: 34 additions & 5 deletions src/Clap-Core/ClapContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Class {
#superclass : #Object,
#instVars : [
'commandCandidates',
'arguments'
'arguments',
'session'
],
#category : #'Clap-Core-Activation'
}
Expand Down Expand Up @@ -47,11 +48,21 @@ ClapContext class >> withPragmaCommands [
^ self withAll: self pragmaCommands
]

{ #category : #activation }
ClapContext >> activateWith: args [
^ self
activateWith: args
onExit: [ :exit | self handleExit: exit ]
]

{ #category : #activation }
ClapContext >> activateWith: args onExit: exitBlock [
^ [ self interpret: args ]
on: Exit
do: exitBlock
^ [ self
rememberSession;
interpret: args
]
on: Exit
do: exitBlock
]

{ #category : #accessing }
Expand Down Expand Up @@ -116,7 +127,20 @@ ClapContext >> exitSuccess: message [

{ #category : #activation }
ClapContext >> handleExit: exit [
self notYetImplemented
^ self hasSessionChanged
ifTrue: [ self ]
ifFalse: [
Smalltalk isInteractive
ifTrue: [
exit isSuccess
ifFalse: [ exit resignalAs: (Error new messageText: exit messageText) ] ]
ifFalse: [ exit pass ]
]
]

{ #category : #activation }
ClapContext >> hasSessionChanged [
^ session ~~ Smalltalk session
]

{ #category : #initialization }
Expand Down Expand Up @@ -149,6 +173,11 @@ ClapContext >> peek [
^ self arguments peek
]

{ #category : #activation }
ClapContext >> rememberSession [
session := Smalltalk session
]

{ #category : #accessing }
ClapContext >> stderr [
^ VTermOutputDriver stderr
Expand Down

0 comments on commit 311478c

Please sign in to comment.