UNPKG

cleanifix

Version:

Intelligent data cleaning CLI with natural language support - Docker-powered Python engine

159 lines 6.99 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const packageJson = __importStar(require("../package.json")); const validate_1 = require("./commands/validate"); const transform_1 = require("./commands/transform"); const analyze_1 = require("./commands/analyze"); const clean_1 = require("./commands/clean"); const config_1 = require("./commands/config"); const init_1 = require("./commands/init"); const logger_1 = require("./utils/logger"); const program = new commander_1.Command(); program .name('cleanifix') .description('Data validation and transformation CLI') .version(packageJson.version) .option('-v, --verbose', 'Enable verbose logging') .option('-q, --quiet', 'Suppress non-error output') .hook('preAction', (thisCommand) => { const options = thisCommand.opts(); if (options.verbose) { process.env.LOG_LEVEL = 'debug'; } else if (options.quiet) { process.env.LOG_LEVEL = 'error'; } }); // Initialize project program .command('init') .description('Initialize a new Cleanifix project') .option('-t, --template <template>', 'Project template to use', 'default') .option('-f, --force', 'Overwrite existing configuration') .action(init_1.initCommand); // Validate data program .command('validate') .description('Validate data against defined rules') .argument('<input>', 'Input file or directory path') .option('-c, --config <path>', 'Path to validation config file') .option('-r, --rules <path>', 'Path to custom rules file') .option('-o, --output <path>', 'Output directory for validation reports') .option('-f, --format <format>', 'Output format (json|html|csv)', 'json') .option('--fail-fast', 'Stop on first validation error') .option('--parallel <number>', 'Number of parallel workers', '4') .action(validate_1.validateCommand); // Transform data program .command('transform') .description('Transform data using defined pipelines') .argument('<input>', 'Input file or directory path') .argument('<output>', 'Output file or directory path') .option('-p, --pipeline <path>', 'Path to transformation pipeline config') .option('-m, --mappings <path>', 'Path to field mappings file') .option('-f, --format <format>', 'Output format (csv|json|parquet|excel)') .option('--streaming', 'Enable streaming mode for large files') .option('--chunk-size <size>', 'Chunk size for processing', '10000') .action(transform_1.transformCommand); // Add the analyze command as a subcommand program.addCommand(analyze_1.analyzeCommand); // Clean data program .command('clean') .description('Clean data using predefined or custom rules') .argument('<input>', 'Input file or directory path') .option('-o, --output <path>', 'Output file or directory path') .option('-r, --rules <rules>', 'Comma-separated list of cleaning rules') .option('-c, --config <path>', 'Path to cleaning configuration file') .option('--dry-run', 'Preview changes without applying them') .option('--backup', 'Create backup of original files') .option('--report', 'Generate cleaning report') .option('-m, --missing', 'Clean missing values') .option('-d, --duplicates', 'Clean duplicate rows') .option('-s, --strategy <strategy>', 'Cleaning strategy: drop, fill, forward_fill, interpolate (for missing), first, last, merge (for duplicates)') .option('-f, --fill-value <value>', 'Fill value: mean, median, mode, or custom value') .option('--columns <columns>', 'Comma-separated list of columns to clean') .option('--subset <subset>', 'Columns to consider for duplicate detection (comma-separated)') .option('-t, --threshold <threshold>', 'Threshold for dropping columns (0-1)') .option('--aggregation-rules <rules>', 'JSON string with aggregation rules for merge strategy') .action(clean_1.cleanCommand); // Manage configuration program .command('config') .description('Manage Cleanifix configuration') .option('-l, --list', 'List all configuration settings') .option('-g, --get <key>', 'Get a configuration value') .option('-s, --set <key=value>', 'Set a configuration value') .option('-r, --reset', 'Reset configuration to defaults') .option('--global', 'Use global configuration') .action(config_1.configCommand); // Error handling program.exitOverride(); try { program.parse(process.argv); } catch (error) { if (error.code === 'commander.helpDisplayed' || error.code === 'commander.version' || error.code === 'commander.help') { // Help or version was displayed, exit successfully process.exit(0); } else if (error.code === 'commander.unknownCommand') { logger_1.logger.error(`Unknown command: ${error.message}`); logger_1.logger.info('Run "cleanifix --help" to see available commands'); process.exit(1); } else if (error.code === 'commander.missingArgument') { logger_1.logger.error(`Missing required argument: ${error.message}`); process.exit(1); } else if (error.code === 'commander.unknownOption') { logger_1.logger.error(`Unknown option: ${error.message}`); process.exit(1); } else { logger_1.logger.error('An unexpected error occurred:', error); process.exit(1); } } // Show help if no command provided if (!process.argv.slice(2).length) { process.stdout.write(program.helpInformation() + '\n', () => { process.exit(0); }); } //# sourceMappingURL=index.js.map