or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdconfiguration.mdevent-system.mdfile-operations.mdindex.mdtask-system.mdtemplating.md
tile.json

cli.mddocs/

Command Line Interface

Command-line interface with option parsing, help system, task discovery, and execution control. Supports various CLI flags, runtime configuration, and comprehensive help system.

Capabilities

Command Line Execution

Execute Grunt tasks from the command line with various options and flags.

Basic CLI Usage:

# Run default task
grunt

# Run specific tasks
grunt build
grunt clean build test

# Run task with target
grunt concat:dev
grunt uglify:prod

# Run task with arguments
grunt deploy:staging --env=prod
grunt test:unit --reporter=spec

# Display help
grunt --help

# Display version
grunt --version

Option Management

Access and manage command-line options within tasks.

/**
 * Get or set command-line option value
 * @param {string} key - Option key
 * @param {*} [value] - Value to set (if provided)
 * @returns {*} Option value
 */
grunt.option = function(key, value) {};

/**
 * Initialize options with object
 * @param {object} obj - Options object
 */
grunt.option.init = function(obj) {};

/**
 * Get array of options formatted as CLI flags
 * @returns {string[]} Array of flag strings
 */
grunt.option.flags = function() {};

/**
 * Get array of all option keys
 * @returns {string[]} Array of option keys
 */
grunt.option.keys = function() {};

Usage Examples:

// Access command-line options in tasks
grunt.registerTask('deploy', function() {
  const env = grunt.option('env') || 'development';
  const force = grunt.option('force');
  const verbose = grunt.option('verbose');
  
  grunt.log.writeln('Deploying to environment: ' + env);
  
  if (force) {
    grunt.log.writeln('Force deployment enabled');
  }
});

// Set options programmatically
grunt.option('target', 'production');
grunt.option('minify', true);

// Initialize multiple options
grunt.option.init({
  env: 'staging',
  debug: false,
  timeout: 30000
});

// Get all option flags for logging
const flags = grunt.option.flags();
grunt.log.writeln('CLI flags: ' + flags.join(' '));

// List all available options
const keys = grunt.option.keys();
grunt.log.writeln('Available options: ' + keys.join(', '));

Standard CLI Options

Common command-line options available in Grunt.

// Standard options (available via grunt.option())
const standardOptions = {
  // Display help information
  help: grunt.option('help'),          // --help, -h
  
  // Display version information  
  version: grunt.option('version'),    // --version, -V
  
  // Enable verbose logging
  verbose: grunt.option('verbose'),    // --verbose, -v
  
  // Enable debug logging
  debug: grunt.option('debug'),        // --debug, -d
  
  // Print stack traces on error
  stack: grunt.option('stack'),        // --stack
  
  // Continue despite warnings/errors
  force: grunt.option('force'),        // --force, -f
  
  // Additional task directories
  tasks: grunt.option('tasks'),        // --tasks
  
  // Additional npm task modules
  npm: grunt.option('npm'),            // --npm
  
  // Disable file writes (dry run)
  'no-write': grunt.option('no-write'), // --no-write
  
  // Disable colored output
  'no-color': grunt.option('no-color'), // --no-color
  
  // Specify Gruntfile location
  gruntfile: grunt.option('gruntfile'), // --gruntfile
  
  // Change base directory
  base: grunt.option('base')           // --base
};

Usage Examples:

# Common CLI usage patterns
grunt build --verbose                    # Enable verbose logging
grunt test --force                       # Continue despite failures
grunt deploy --env=production --force    # Custom option with force
grunt --gruntfile=alt/Gruntfile.js build # Use alternative Gruntfile
grunt --base=subproject build            # Run from different directory
grunt clean --no-write                   # Dry run (don't actually delete)
grunt build --stack                      # Show stack traces on errors

Help System

Comprehensive help system for displaying usage information and available tasks.

/**
 * Display complete help information
 */
grunt.help.display = function() {};

/**
 * Display help header
 */
grunt.help.header = function() {};

/**
 * Display usage information
 */
grunt.help.usage = function() {};

/**
 * Display available options table
 */
grunt.help.options = function() {};

/**
 * Display available tasks
 */
grunt.help.tasks = function() {};

/**
 * Display help footer
 */
grunt.help.footer = function() {};

Usage Examples:

// Display help in custom task
grunt.registerTask('info', function() {
  grunt.help.display();
});

// Custom help display
grunt.registerTask('custom-help', function() {
  grunt.help.header();
  grunt.log.writeln('Custom Project Help');
  grunt.log.writeln('===================');
  grunt.help.tasks();
  grunt.help.footer();
});

// Conditional help based on arguments
grunt.registerTask('setup', function() {
  if (this.args.length === 0) {
    grunt.log.writeln('Usage: grunt setup:<environment>');
    grunt.log.writeln('Available environments: dev, staging, prod');
    return;
  }
  
  const env = this.args[0];
  grunt.log.writeln('Setting up environment: ' + env);
});

CLI Interface Properties

Access CLI parsing results and option definitions.

/**
 * Array of tasks parsed from command line
 * @type {string[]}
 */
grunt.cli.tasks = [];

/**
 * Object of parsed command-line options
 * @type {object}
 */
grunt.cli.options = {};

/**
 * Available CLI options from grunt-known-options
 * @type {object}
 */
grunt.cli.optlist = {};

Usage Examples:

// Access CLI parsing results
grunt.registerTask('debug-cli', function() {
  grunt.log.writeln('Tasks from CLI: ' + grunt.cli.tasks.join(', '));
  grunt.log.writeln('Options from CLI:', JSON.stringify(grunt.cli.options, null, 2));
  
  // Check specific CLI flags
  if (grunt.cli.options.verbose) {
    grunt.log.writeln('Verbose mode enabled via CLI');
  }
});

// List all available CLI options
grunt.registerTask('list-options', function() {
  grunt.log.writeln('Available CLI options:');
  Object.keys(grunt.cli.optlist).forEach(function(option) {
    const optDef = grunt.cli.optlist[option];
    grunt.log.writeln('  --' + option + 
                     (optDef.short ? ', -' + optDef.short : '') +
                     ': ' + optDef.info);
  });
});

Custom CLI Options

Handle custom command-line options in tasks and configuration.

// Task that uses custom CLI options
grunt.registerTask('build', function() {
  // Custom options
  const target = grunt.option('target') || 'dev';
  const optimize = grunt.option('optimize') || false;
  const skipTests = grunt.option('skip-tests') || false;
  
  grunt.log.writeln('Build target: ' + target);
  
  // Configure tasks based on CLI options
  if (optimize) {
    grunt.task.run(['uglify', 'cssmin']);
  }
  
  if (!skipTests) {
    grunt.task.run(['test']);
  }
});

// Configuration based on CLI options
const buildTarget = grunt.option('target') || 'development';
const isProduction = buildTarget === 'production';

grunt.initConfig({
  uglify: {
    options: {
      mangle: isProduction,
      compress: isProduction
    },
    dist: {
      files: {
        'dist/app.min.js': ['src/*.js']
      }
    }
  }
});

CLI Usage Examples:

# Using custom options
grunt build --target=production --optimize
grunt test --reporter=json --timeout=5000
grunt deploy --skip-tests --env=staging

# Complex option combinations
grunt build --target=prod --optimize --no-write --verbose

Environment Integration

Integrate CLI options with environment variables and configuration.

// Merge CLI options with environment variables
grunt.registerTask('config', function() {
  const config = {
    // Environment variables
    nodeEnv: process.env.NODE_ENV || 'development',
    port: process.env.PORT || 3000,
    
    // CLI options override environment
    target: grunt.option('target') || process.env.BUILD_TARGET || 'dev',
    debug: grunt.option('debug') || process.env.DEBUG === 'true',
    
    // CLI-only options
    force: grunt.option('force'),
    verbose: grunt.option('verbose')
  };
  
  grunt.log.writeln('Configuration:', JSON.stringify(config, null, 2));
  
  // Store in grunt config for other tasks
  grunt.config.set('app', config);
});

// Conditional task execution based on CLI
grunt.registerTask('default', function() {
  const tasks = ['clean', 'build'];
  
  // Add optional tasks based on CLI flags
  if (grunt.option('test')) {
    tasks.push('test');
  }
  
  if (grunt.option('deploy')) {
    tasks.push('deploy');
  }
  
  grunt.task.run(tasks);
});

CLI Error Handling

Handle CLI-related errors and provide user feedback.

// Validate CLI options
grunt.registerTask('validate-options', function() {
  const validTargets = ['dev', 'staging', 'prod'];
  const target = grunt.option('target');
  
  if (target && validTargets.indexOf(target) === -1) {
    grunt.fail.fatal('Invalid target: ' + target + 
                     '. Valid targets: ' + validTargets.join(', '));
  }
  
  const timeout = grunt.option('timeout');
  if (timeout && isNaN(parseInt(timeout))) {
    grunt.fail.warn('Timeout must be a number, got: ' + timeout);
  }
});

// Provide helpful error messages
grunt.registerTask('deploy', function() {
  if (!grunt.option('env')) {
    grunt.fail.fatal('Deploy requires --env option. ' +
                     'Usage: grunt deploy --env=<environment>');
  }
  
  if (!grunt.file.exists('deploy.config.json')) {
    grunt.fail.fatal('Deploy configuration not found. ' +
                     'Run: grunt setup --env=' + grunt.option('env'));
  }
});