Class: Fasti::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/fasti/cli.rb

Overview

Command-line interface for the fasti calendar application.

This class handles all CLI functionality including option parsing, validation, and calendar generation. It supports various display formats and customization options while maintaining backwards compatibility.

## Usage Positional arguments for month/year specification:

  • 0 args: current month + current year

  • 1 arg: 1-12 → month + current year, 13+ → current month + year

  • 2 args: month year (first arg = month 1-12, second arg = year)

## Options

  • ‘–format, -f`: Display format (month/quarter/year, default: month)

  • ‘–start-of-week, -w`: Week start (sunday/monday, default: sunday)

  • ‘–country, -c`: Country code for holidays (auto-detected from LANG/LC_ALL, supports many countries)

  • ‘–style, -s`: Custom styling for different day types (e.g., “sunday:bold holiday:foreground=red”)

  • ‘–version, -v`: Show version information

  • ‘–help, -h`: Show help message

## Configuration File Default options can be specified in a configuration file:

  • Path: ‘$XDG_CONFIG_HOME/fasti/config.rb` (or `$HOME/.config/fasti/config.rb` if XDG_CONFIG_HOME is unset)

  • Format: Ruby DSL using Fasti.configure block

  • Precedence: Command line options override config file options

Examples:

Basic usage

CLI.run(["6", "2024"])  # June 2024

Month only

CLI.run(["6"])  # June current year

Year only

CLI.run(["2024"])  # Current month 2024

Year view

CLI.run(["2024", "--format", "year", "--country", "US"])

Config file content ($HOME/.config/fasti/config.rb)

Fasti.configure do |config|
  config.format = :quarter
  config.start_of_week = :monday
  config.country = :US
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(argv) ⇒ Object

Runs the CLI with the specified arguments.

Parameters:

  • argv (Array<String>)

    Command line arguments to parse



67
68
69
# File 'lib/fasti/cli.rb', line 67

def self.run(argv)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object

Runs the CLI instance with the specified arguments.

Parameters:

  • argv (Array<String>)

    Command line arguments to parse



74
75
76
77
78
79
80
81
82
# File 'lib/fasti/cli.rb', line 74

def run(argv)
  @current_time = Time.now # Single source of truth for time
  catch(:early_exit) do
    month, year, options = parse_arguments(argv)
    generate_calendar(month, year, options)
  end
rescue => e
  handle_error(e)
end