@@ -7,15 +7,39 @@ export const createAddressBookCommand = () => {
77 . description (
88 "Prints the addresses of all smart contracts deployed to the runtime environment of the application." ,
99 )
10+ . argument (
11+ "[contract]" ,
12+ "name of a contract; when provided, prints only its address (useful for scripting)" ,
13+ )
1014 . option ( "--json" , "Format output as json." )
1115 . option (
1216 "--project-name <string>" ,
1317 "name of project (used by docker compose and cartesi-rollups-node)" ,
1418 )
15- . action ( async ( options ) => {
19+ . action ( async ( contract , options , command ) => {
1620 const { json } = options ;
1721 const projectName = getProjectName ( options ) ;
1822 const addressBook = await getAddressBook ( { projectName } ) ;
23+
24+ if ( contract !== undefined ) {
25+ // look up a single contract by name (case-insensitive)
26+ const entry = Object . entries ( addressBook ) . find (
27+ ( [ name ] ) => name . toLowerCase ( ) === contract . toLowerCase ( ) ,
28+ ) ;
29+ if ( ! entry ) {
30+ command . error ( `Contract not found: ${ contract } ` ) ;
31+ return ;
32+ }
33+ const [ , address ] = entry ;
34+ if ( ! json ) {
35+ // print only the address, for easy shell integration
36+ console . log ( address ) ;
37+ } else {
38+ process . stdout . write ( JSON . stringify ( address ) ) ;
39+ }
40+ return ;
41+ }
42+
1943 if ( ! json ) {
2044 // print as a table
2145 const table = new Table ( {
0 commit comments