argumentDefinition = new ezcConsoleArguments(); $inFile = new ezcConsoleArgument( 'inFile' ); $inFile->shorthelp = 'Input file.'; $inFile->longhelp = 'File to take as input for conversion.'; $outFile = new ezcConsoleArgument( 'outFile' ); $outFile->shorthelp = 'Output file.'; $outFile->longhelp = 'File to output converted document to.'; $input->argumentDefinition[0] = $inFile; $input->argumentDefinition[1] = $outFile; $helpOpt = new ezcConsoleOption( 'h', 'help' ); $helpOpt->shorthelp = 'Show help.'; $helpOpt->longhelp = 'Show information about using this tool.'; $helpOpt->isHelpOption = true; $input->registerOption( $helpOpt ); $inFormat = new ezcConsoleOption( 'i', 'input-format' ); $inFormat->shorthelp = 'Format of the input file.'; $inFormat->longhelp = 'Format of the input file. Possible values are: ' . implode( ', ', ezcappDocumentConverter::$formats ) . '.'; $inFormat->type = ezcConsoleInput::TYPE_STRING; $input->registerOption( $inFormat ); $outFormat = new ezcConsoleOption( 'o', 'output-format' ); $outFormat->shorthelp = 'Format of the output file.'; $outFormat->longhelp = 'Format of the output file. Possible values are: ' . implode( ', ', ezcappDocumentConverter::$formats ) . '.'; $outFormat->type = ezcConsoleInput::TYPE_STRING; $input->registerOption( $outFormat ); try { $input->process(); } catch ( ezcConsoleException $e ) { $output->outputLine( "Error: " . $e->getMessage() ); $output->outputText( $input->getHelpText( 'Document converter', 80 ) ); exit( -1 ); } if ( $input->helpOptionSet() ) { $output->outputText( $input->getHelpText( 'Document converter', 80, true ) ); exit( 0 ); } if ( $inFormat->value !== false && !in_array( $inFormat->value, ezcappDocumentConverter::$formats ) ) { $output->outputLine( "Invalid input format '{$inFormat->value}'." ); exit( -2 ); } if ( $outFormat->value !== false && !in_array( $outFormat->value, ezcappDocumentConverter::$formats ) ) { $output->outputLine( "Invalid output format '{$outFormat->value}'." ); exit( -2 ); } if ( !file_exists( $inFile->value ) ) { $output->outputLine( "Could not read input file '$inFile->value'." ); exit( -3 ); } if ( $inFormat->value !== false && $outFormat->value !== false && $inFormat->value === $outFormat->value ) { copy( $inFile->value, $outFile->value ); exit( 0 ); } try { $converter = new ezcappDocumentConverter( $inFormat->value, $outFormat->value ); $converter->convert( $inFile->value, $outFile->value ); } catch ( Exception $e ) { $output->outputLine( 'Conversion error: ' . $e->getMessage() ); exit( -4 ); } $output->outputLine( 'Converted successfully.' ); exit( 0 ); ?>