11import { Command } from "commander" ;
22import * as readline from "readline" ;
33import { resolveProfile } from "../config.js" ;
4+ import { formatOutput , formatError , isJsonMode } from "../format.js" ;
45
56export interface PauseResult {
67 txHash : string ;
@@ -50,20 +51,23 @@ export function makePauseCommand(
5051 cmd
5152 . option ( "--yes" , "Skip confirmation prompt" )
5253 . action ( async ( opts : { yes ?: boolean } ) => {
54+ const rootOpts = cmd . parent ?. opts ( ) as Record < string , unknown > | undefined ;
55+ const json = isJsonMode ( rootOpts ) ;
56+
5357 try {
5458 // Require admin authentication
55- const parentOpts = cmd . parent ?. opts ( ) as { profile ?: string } | undefined ;
56- const profile = resolveProfile ( parentOpts ?. profile ) ;
59+ const profile = resolveProfile ( rootOpts ?. profile as string | undefined ) ;
5760 if ( ! profile ) {
58- console . error ( "Error: No connected wallet found. Run: iln wallet generate" ) ;
59- process . exit ( 1 ) ;
61+ formatError ( "No connected wallet found. Run: iln wallet generate" , "NO_WALLET" , json ) ;
6062 return ;
6163 }
6264
6365 // Check current state
6466 const isCurrentlyPaused = await stateChecker ( ) ;
6567 if ( isCurrentlyPaused ) {
66- console . log ( "Contract is already paused. No changes made." ) ;
68+ formatOutput ( { paused : true , message : "contract is already paused" } , json , ( ) => {
69+ console . log ( "Contract is already paused. No changes made." ) ;
70+ } ) ;
6771 return ;
6872 }
6973
@@ -72,7 +76,9 @@ export function makePauseCommand(
7276 const msg = "Confirm pause of contract? [y/N]" ;
7377 const confirmed = await confirm ( msg ) ;
7478 if ( ! confirmed ) {
75- console . log ( "Aborted — contract not paused." ) ;
79+ formatOutput ( { aborted : true , message : "contract not paused" } , json , ( ) => {
80+ console . log ( "Aborted — contract not paused." ) ;
81+ } ) ;
7682 return ;
7783 }
7884 }
@@ -81,11 +87,12 @@ export function makePauseCommand(
8187 // Update defaultState if using defaultStateChecker
8288 defaultState = true ;
8389
84- console . log ( `Contract paused. TX: ${ result . txHash } ` ) ;
85- console . log ( `Contract State: Paused` ) ;
90+ formatOutput ( { ...result , state : "Paused" } , json , ( ) => {
91+ console . log ( `Contract paused. TX: ${ result . txHash } ` ) ;
92+ console . log ( `Contract State: Paused` ) ;
93+ } ) ;
8694 } catch ( err ) {
87- console . error ( `Error: ${ ( err as Error ) . message } ` ) ;
88- process . exit ( 1 ) ;
95+ formatError ( ( err as Error ) . message , "PAUSE_ERROR" , json ) ;
8996 }
9097 } ) ;
9198
@@ -102,20 +109,23 @@ export function makeUnpauseCommand(
102109 cmd
103110 . option ( "--yes" , "Skip confirmation prompt" )
104111 . action ( async ( opts : { yes ?: boolean } ) => {
112+ const rootOpts = cmd . parent ?. opts ( ) as Record < string , unknown > | undefined ;
113+ const json = isJsonMode ( rootOpts ) ;
114+
105115 try {
106116 // Require admin authentication
107- const parentOpts = cmd . parent ?. opts ( ) as { profile ?: string } | undefined ;
108- const profile = resolveProfile ( parentOpts ?. profile ) ;
117+ const profile = resolveProfile ( rootOpts ?. profile as string | undefined ) ;
109118 if ( ! profile ) {
110- console . error ( "Error: No connected wallet found. Run: iln wallet generate" ) ;
111- process . exit ( 1 ) ;
119+ formatError ( "No connected wallet found. Run: iln wallet generate" , "NO_WALLET" , json ) ;
112120 return ;
113121 }
114122
115123 // Check current state
116124 const isCurrentlyPaused = await stateChecker ( ) ;
117125 if ( ! isCurrentlyPaused ) {
118- console . log ( "Contract is already unpaused. No changes made." ) ;
126+ formatOutput ( { paused : false , message : "contract is already unpaused" } , json , ( ) => {
127+ console . log ( "Contract is already unpaused. No changes made." ) ;
128+ } ) ;
119129 return ;
120130 }
121131
@@ -124,7 +134,9 @@ export function makeUnpauseCommand(
124134 const msg = "Confirm unpause of contract? [y/N]" ;
125135 const confirmed = await confirm ( msg ) ;
126136 if ( ! confirmed ) {
127- console . log ( "Aborted — contract not unpaused." ) ;
137+ formatOutput ( { aborted : true , message : "contract not unpaused" } , json , ( ) => {
138+ console . log ( "Aborted — contract not unpaused." ) ;
139+ } ) ;
128140 return ;
129141 }
130142 }
@@ -133,11 +145,12 @@ export function makeUnpauseCommand(
133145 // Update defaultState if using defaultStateChecker
134146 defaultState = false ;
135147
136- console . log ( `Contract unpaused. TX: ${ result . txHash } ` ) ;
137- console . log ( `Contract State: Active` ) ;
148+ formatOutput ( { ...result , state : "Active" } , json , ( ) => {
149+ console . log ( `Contract unpaused. TX: ${ result . txHash } ` ) ;
150+ console . log ( `Contract State: Active` ) ;
151+ } ) ;
138152 } catch ( err ) {
139- console . error ( `Error: ${ ( err as Error ) . message } ` ) ;
140- process . exit ( 1 ) ;
153+ formatError ( ( err as Error ) . message , "UNPAUSE_ERROR" , json ) ;
141154 }
142155 } ) ;
143156
0 commit comments