BashCommand class

A Command that wraps a bash script

Easy way to convert an existing bash script into a command for sidekick

This makes it easy to handle paths within the bash script. You can define a static workingDirectory and always know where the script is executed.

Usage as plain text

runner
  ..addCommand(
     BashCommand(
       name: 'test-bash-command',
       description: 'Prints inputs of a sidekick BashCommand',
       workingDirectory: runner.repository.root,
       script: () => '''
echo "arguments: \$@"
echo "workingDirectory: \$(pwd)"
# Access paths from sidekick
${systemFlutterSdkPath()}/bin/flutter --version
''',
    ),
  );

Or load your script from a file

runner
  ..addCommand(
    BashCommand(
      name: 'test-bash-command',
      description: 'Prints inputs of a sidekick BashCommand',
      workingDirectory: runner.repository.root,
      script: () => runner.repository.root
          .file('scripts/test-bash-command.sh')
          .readAsString(),
    ),
  )

If your script is interactive, set withStdIn to true to allow stdin to be connected to the script.

Inheritance

Constructors

BashCommand({required FutureOr<String> script(), required String description, required String name, Directory? workingDirectory, bool withStdIn = false})

Properties

aliases List<String>
Alternate names for this command.
no setterinherited
argParser ArgParser
The argument parser for this command.
no setterinherited
argResults ArgResults?
The parsed argument results for this command.
no setterinherited
category String
The command's category.
no setterinherited
description String
A description of this command, included in usage.
final
globalResults ArgResults?
The parsed global argument results.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
hidden bool
Whether or not this command should be hidden from help listings.
no setterinherited
invocation String
A single-line template for how to invoke this command (e.g. "pub get package").
no setterinherited
name String
The name of this command.
final
parent Command?
The command's parent command, if this is a subcommand.
no setterinherited
runner CommandRunner?
The command runner for this command.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
script FutureOr<String> Function()
The script to be executed.
final
subcommands Map<String, Command>
An unmodifiable view of all sublevel commands of this command.
no setterinherited
suggestionAliases List<String>
Alternate non-functional names for this command.
no setterinherited
summary String
A short description of this command, included in parent's CommandRunner.usage.
no setterinherited
takesArguments bool
Whether or not this command takes positional arguments in addition to options.
no setterinherited
usage String
Generates a string displaying usage information for this command.
no setterinherited
usageFooter String?
An optional footer for usage.
no setterinherited
withStdIn bool
Whether to forward stdin to the bash script, default to true
final
workingDirectory Directory?
The directory the bash script is running in.
final

Methods

addSubcommand(Command command) → void
Adds Command as a subcommand of this.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
printUsage() → void
Prints the usage information for this command.
inherited
run() Future<void>
Runs this command.
override
toString() String
A string representation of this object.
inherited
usageException(String message) → Never
Throws a UsageException with message.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited