Skip to content

Commit

Permalink
docs: Add for command
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiJingLong committed May 19, 2023
1 parent 8acb6e6 commit a68b967
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/github_action_core/lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@ import 'package:uuid/uuid.dart';

import 'utils.dart';

/// Issues a command to the job step.
void issueCommand(
String command, Map<String, dynamic> properties, dynamic message) {
final cmd = Command(command, properties, message);
stdout.write('${cmd.toString()}${Platform.operatingSystem}');
}

/// Issues a command with a given name and optional message.
void issue(String name, {String message = ''}) {
issueCommand(name, {}, message);
}

/// The command string prefix.
const _cmdString = '::';

/// Represents a command with properties and a message.
class Command {
/// The command name.
String command;

/// The properties associated with the command.
final Map<String, dynamic> properties;

/// The message of the command.
final String message;

/// Creates a new instance of the [Command] class.
Command(this.command, this.properties, this.message) {
if (command.isEmpty) {
command = 'missing.command';
Expand Down Expand Up @@ -55,13 +65,15 @@ class Command {
}
}

/// Escapes the command data by replacing special characters.
String escapeData(dynamic s) {
return toCommandValue(s)
.replaceAll('%', '%25')
.replaceAll('\r', '%0D')
.replaceAll('\n', '%0A');
}

/// Escapes the command property by replacing special characters.
String escapeProperty(dynamic s) {
return toCommandValue(s)
.replaceAll('%', '%25')
Expand All @@ -71,6 +83,7 @@ String escapeProperty(dynamic s) {
.replaceAll(',', '%2C');
}

/// Issues a file command with a command name and a message.
void issueFileCommand(String command, dynamic message) {
final filePath = Platform.environment['GITHUB_$command'];
if (filePath == null) {
Expand All @@ -86,6 +99,7 @@ void issueFileCommand(String command, dynamic message) {
mode: FileMode.append, encoding: utf8);
}

/// Prepares a key-value message with a delimiter for a command.
String prepareKeyValueMessage(String key, dynamic value) {
final delimiter = 'ghadelimiter_${Uuid().v4()}';
final convertedValue = toCommandValue(value);
Expand Down

0 comments on commit a68b967

Please sign in to comment.