import yargs , { exit } from 'yargs' ; import logger from 'loglevel' ; import initFiglet from './init-figlet' ; import { readCommandHandler , writeCommandHandler , createCommandHandler } from './handlers' ; import messages from '../static/cli-command-messages.json' ; initFiglet ( messages . common . figletText ) ; const readCommand = { command : 'read <contractId>' , describe : messages . commands . readCommand . description , builder : ( ) => yargs . options ( { input : { describe : messages . commands . readCommand . options . input . description , demandOption : false , } , prettify : { describe : messages . commands . readCommand . options . prettify . description , } , } ) . positional ( 'contractId' , { describe : messages . commands . readCommand . positionals . contractId . description , } ) , handler : readCommandHandler , } ; const writeCommand = { command : 'write <contractId>' , describe : 'Writes an interaction with contract, or simulates a write interaction.' , builder : ( ) => yargs . options ( { 'key-file' : { describe : 'Your key file' , demandOption : true , } , input : { describe : 'Input to the contract' , demandOption : true , } , 'dry-run' : { describe : 'Simulate interaction and output contract state' , boolean : true , } , prettify : { describe : 'If set prints the eventual output state as a stringified and prettified JSON' , } , tags : { describe : 'The tags to be sent along with the Contract interaction. They should be a string containing an array of Objects {name:tagName, value:tagValue} (i.e. \'[{"name":"arweave", "value":"rocks"},{"name":"smartweave", "value":"rocks too"}]\')' , } , quantity : { describe : 'The amount of winston to be sent along with the Contract interaction' , } , target : { describe : 'The wallet to which send the winston send along with the Contract interaction' , } , } ) . positional ( 'contractId' , { describe : 'The Contract ID' , } ) , handler : writeCommandHandler , } ; const createCommand = { command : 'create <contractSource> <initStateFile>' , describe : 'Creates a new contract from a source file or existing contract source already on-chain.' , builder : ( ) => yargs . options ( { 'key-file' : { describe : 'Your key file' , demandOption : true , } , } ) . positional ( 'contractSource' , { describe : 'The contract source. A path to a .js file, or transaction id' } ) . positional ( 'initStateFile' , { describe : 'The initial state of the contract. Path to a .json file' } ) , handler : createCommandHandler , } ; yargs . command ( readCommand ) . command ( writeCommand ) . command ( createCommand ) . demandCommand ( ) . help ( ) . argv ;