diff --git a/lib/oto/commands/command.dart b/lib/oto/commands/command.dart index 09ef54f..6fd0dbb 100644 --- a/lib/oto/commands/command.dart +++ b/lib/oto/commands/command.dart @@ -77,6 +77,7 @@ enum CommandType { Shell, ShellFile, Git, + GitCommit, GitPush, GitCheckout, GitRev, @@ -138,6 +139,7 @@ abstract class Command { CommandType.Shell: () => Shell(), CommandType.ShellFile: () => ShellFile(), CommandType.Git: () => Git(), + CommandType.GitCommit: () => GitCommit(), CommandType.GitPush: () => GitPush(), CommandType.GitCheckout: () => GitCheckout(), CommandType.GitRev: () => GitRev(), diff --git a/lib/oto/commands/git/git.dart b/lib/oto/commands/git/git.dart index c7ef572..1a27458 100644 --- a/lib/oto/commands/git/git.dart +++ b/lib/oto/commands/git/git.dart @@ -19,6 +19,27 @@ class Git extends Command { } } +//무시가가능한 에러 무시 +class GitCommit extends Command { + @override + Future execute(DataCommand command) async { + var data = DataGitCommit.fromJson(getParam(command)); + + var shell = StringBuffer(getCDPath(workspace)); + var addNewFile = data.addNewFile == null ? false : data.addNewFile!; + var message = data.message; + + if(addNewFile) { + shell.write(' && git add -A && git commit -m "$message"'); + } else { + shell.write(' && git commit -am "$message"'); + } + + var process = await ProcessExecutor.start(shell); + return await completeProcess(process, command); + } +} + //무시가가능한 에러 무시 class GitPush extends Command { @override diff --git a/lib/oto/commands/shell/shell.dart b/lib/oto/commands/shell/shell.dart index 6d5295b..7641da3 100644 --- a/lib/oto/commands/shell/shell.dart +++ b/lib/oto/commands/shell/shell.dart @@ -14,8 +14,17 @@ class Shell extends Command { shell.write(' && $item'); } - var process = await ProcessExecutor.start(shell); - return await completeProcess(process, command); + if(data.setMessage == null) { + var process = await ProcessExecutor.start(shell); + return await completeProcess(process, command); + } else { + var process = await ProcessExecutor.run(shell); + var str = process.stdout.toString(); + var length = str.length; + str = str.substring(0, length - 1); + await setProperty(data.setMessage!, str); + return await complete(process.exitCode, command); + } } } diff --git a/lib/oto/commands/util/string_util.dart b/lib/oto/commands/util/string_util.dart index 556cc4e..6c7337b 100644 --- a/lib/oto/commands/util/string_util.dart +++ b/lib/oto/commands/util/string_util.dart @@ -32,7 +32,12 @@ class StringReplace extends Command { try { - text = text.replaceAll(data.from, data.to); + if(data.fromRegExp != null) { + text = text.replaceAll(RegExp(data.fromRegExp!), data.to); + } + if(data.from != null) { + text = text.replaceAll(data.from!, data.to); + } await setProperty(data.setValue, text, showPrint: data.showPrint); } on Exception { diff --git a/lib/oto/data/command_data.dart b/lib/oto/data/command_data.dart index 872db09..aed27a0 100644 --- a/lib/oto/data/command_data.dart +++ b/lib/oto/data/command_data.dart @@ -551,6 +551,7 @@ class DataShell extends DataParam { DataShell(); late List commands; + late String? setMessage; factory DataShell.fromJson(Map json) => _$DataShellFromJson(json); @@ -583,6 +584,20 @@ class DataGit extends DataParam { Map toJson() => _$DataGitToJson(this); } +//GitCommit +@JsonSerializable() +class DataGitCommit extends DataParam { + DataGitCommit(); + + late bool? addNewFile; + late String message; + + factory DataGitCommit.fromJson(Map json) => + _$DataGitCommitFromJson(json); + @override + Map toJson() => _$DataGitCommitToJson(this); +} + //GitPush @JsonSerializable() class DataGitPush extends DataParam { @@ -873,7 +888,8 @@ class DataStringReplace extends DataParam { late String text; late String setValue; - late String from; + late String? from; + late String? fromRegExp; late String to; factory DataStringReplace.fromJson(Map json) => diff --git a/lib/oto/data/command_data.g.dart b/lib/oto/data/command_data.g.dart index dd9e095..6ac5a2b 100644 --- a/lib/oto/data/command_data.g.dart +++ b/lib/oto/data/command_data.g.dart @@ -69,6 +69,7 @@ const _$CommandTypeEnumMap = { CommandType.Shell: 'Shell', CommandType.ShellFile: 'ShellFile', CommandType.Git: 'Git', + CommandType.GitCommit: 'GitCommit', CommandType.GitPush: 'GitPush', CommandType.GitCheckout: 'GitCheckout', CommandType.GitRev: 'GitRev', @@ -967,7 +968,8 @@ DataShell _$DataShellFromJson(Map json) => DataShell() ..setExitCode = json['setExitCode'] as String? ..showPrint = json['showPrint'] as bool? ..commands = - (json['commands'] as List).map((e) => e as String).toList(); + (json['commands'] as List).map((e) => e as String).toList() + ..setMessage = json['setMessage'] as String?; Map _$DataShellToJson(DataShell instance) => { 'workspace': instance.workspace, @@ -976,6 +978,7 @@ Map _$DataShellToJson(DataShell instance) => { 'setExitCode': instance.setExitCode, 'showPrint': instance.showPrint, 'commands': instance.commands, + 'setMessage': instance.setMessage, }; DataShellFile _$DataShellFileFromJson(Map json) => @@ -1019,6 +1022,29 @@ Map _$DataGitToJson(DataGit instance) => { 'commands': instance.commands, }; +DataGitCommit _$DataGitCommitFromJson(Map json) => + DataGitCommit() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => (e as num).toInt()) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..showPrint = json['showPrint'] as bool? + ..addNewFile = json['addNewFile'] as bool? + ..message = json['message'] as String; + +Map _$DataGitCommitToJson(DataGitCommit instance) => + { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'showPrint': instance.showPrint, + 'addNewFile': instance.addNewFile, + 'message': instance.message, + }; + DataGitPush _$DataGitPushFromJson(Map json) => DataGitPush() ..workspace = json['workspace'] as String? ..passExitCodes = (json['passExitCodes'] as List?) @@ -1469,7 +1495,8 @@ DataStringReplace _$DataStringReplaceFromJson(Map json) => ..showPrint = json['showPrint'] as bool? ..text = json['text'] as String ..setValue = json['setValue'] as String - ..from = json['from'] as String + ..from = json['from'] as String? + ..fromRegExp = json['fromRegExp'] as String? ..to = json['to'] as String; Map _$DataStringReplaceToJson(DataStringReplace instance) => @@ -1482,6 +1509,7 @@ Map _$DataStringReplaceToJson(DataStringReplace instance) => 'text': instance.text, 'setValue': instance.setValue, 'from': instance.from, + 'fromRegExp': instance.fromRegExp, 'to': instance.to, };