GitIgnoreCommand

Class
extends Command
Final: Yes

Provides functionality to merge and synchronize .gitignore files.

Description

This command merges the canonical .gitignore from dev-tools with the project's existing .gitignore, removing duplicates and sorting entries.

The command accepts two options: --source and --target to specify the paths to the canonical and project .gitignore files respectively.

Attributes
#[AsCommand]
$name : 'git:ignore'
$description : 'Merges and synchronizes .gitignore files.'
$aliases : ['.gitignore', 'gitignore']

Table of Contents

Constants

 = '.gitignore'

Properties

Methods

__construct()

Creates a new GitIgnoreCommand instance.

 : mixed
addJsonOption()

Adds the standard JSON output options to the current command.

 : static
configure()

Configures the current command.

 : void
execute()

Executes the gitignore merge process.

 : int
isJsonOutput()

Determines whether JSON output was requested.

 : bool
isPrettyJsonOutput()

Determines whether pretty JSON output was requested.

 : bool
failure()

Logs a failed command result and returns the failure exit code.

 : int
isImplicitJsonOutputEnabled()

Determines whether structured JSON output SHOULD be enabled implicitly.

 : bool
isOptionEnabled()

Determines whether a boolean input option was enabled.

 : bool
log()

Logs a non-terminal command message unless structured JSON output is active.

 : void
shouldWriteGitIgnore()

Prompts whether .gitignore should be updated.

 : bool
success()

Logs a successful command result and returns the success exit code.

 : int
Constants

Constants

FILENAME

Public
public string FILENAME = '.gitignore'

Description

the default filename for .gitignore files

Properties

$fileLocator

Private Read-only
private FileLocatorInterface $fileLocator
Methods

__construct()

Public

Creates a new GitIgnoreCommand instance.

public __construct(MergerInterface  $merger, ReaderInterface  $reader, WriterInterface|null  $writer, FileLocatorInterface  $fileLocator, FileDiffer  $fileDiffer, SymfonyStyle  $io) : mixed
Parameters
$merger : MergerInterface

Description

the merger component

$reader : ReaderInterface

Description

the reader component

$writer : WriterInterface|null

Description

the writer component

$fileLocator : FileLocatorInterface

Description

the file locator

$fileDiffer : FileDiffer

Description

the file differ used to summarize synchronization changes

$io : SymfonyStyle

Description

the input/output service used to interact with the user

addJsonOption()

Protected

Adds the standard JSON output options to the current command.

protected addJsonOption() : static
Return values
static

configure()

Protected

Configures the current command.

protected configure() : void

Description

This method MUST define the name, description, and help text for the command. It SHALL identify the tool as the mechanism for script synchronization.

execute()

Protected

Executes the gitignore merge process.

protected execute(InputInterface  $input, OutputInterface  $output) : int
Parameters
$input : InputInterface

Description

the input interface

$output : OutputInterface

Description

the output interface

Return values
int

Description

the status code

isJsonOutput()

Protected

Determines whether JSON output was requested.

protected isJsonOutput(InputInterface  $input) : bool

Description

The pretty-json flag SHALL imply JSON output.

Parameters
$input : InputInterface
Return values
bool

isPrettyJsonOutput()

Protected

Determines whether pretty JSON output was requested.

protected isPrettyJsonOutput(InputInterface  $input) : bool
Parameters
$input : InputInterface
Return values
bool

failure()

Private

Logs a failed command result and returns the failure exit code.

private failure( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string|null  $file = null][, int|null  $line = null]) : int
Parameters
$message : string

Description

the failure message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

$file : string|null = null

Description

the related file path when known

$line : int|null = null

Description

the related line when known

Return values
int

isImplicitJsonOutputEnabled()

Private

Determines whether structured JSON output SHOULD be enabled implicitly.

private isImplicitJsonOutputEnabled() : bool

Description

Commands MAY opt into runtime-environment-aware behavior by exposing a $runtimeEnvironment property. Commands that do not expose it SHALL fall back to the shared runtime-environment service from the DevTools container.

Return values
bool

isOptionEnabled()

Private

Determines whether a boolean input option was enabled.

private isOptionEnabled(InputInterface  $input, string  $option) : bool
Parameters
$input : InputInterface
$option : string
Return values
bool

log()

Private

Logs a non-terminal command message unless structured JSON output is active.

private log( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string  $logLevel = LogLevel::INFO]) : void
Parameters
$message : string

Description

the progress message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

$logLevel : string = LogLevel::INFO

Description

the PSR-3 log level used for the message

shouldWriteGitIgnore()

Private

Prompts whether .gitignore should be updated.

private shouldWriteGitIgnore( string  $targetPath) : bool
Parameters
$targetPath : string

Description

the target path that would be updated

Return values
bool

Description

true when the update SHOULD proceed

success()

Private

Logs a successful command result and returns the success exit code.

private success( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string  $logLevel = LogLevel::INFO]) : int
Parameters
$message : string

Description

the success message

$input : InputInterface

Description

the originating command input

$context : array<string, mixed> = []

Description

optional extra log context

$logLevel : string = LogLevel::INFO

Description

the PSR-3 log level used for the successful result

Return values
int