Mac Path 등록 완료

This commit is contained in:
Toki 2023-10-29 18:46:58 +09:00
parent 88770edc1b
commit 51bdca733d
5 changed files with 69 additions and 8 deletions

2
.vscode/launch.json vendored
View file

@ -16,7 +16,7 @@
"request": "launch",
"type": "dart",
"program": "./bin/oto_cli.dart",
"args": ["install"]
"args": ["uninstall"]
},
{
"name": "oto_cli_win",

View file

@ -175,7 +175,7 @@ abstract class Printer {
var time =
'${now.hour}${now.minute}${now.second}${now.millisecond}${now.microsecond}';
var tempFile =
File(path.join(Directory.current.path, 'temp_$time.$extension'));
File(path.join(Directory.systemTemp.path, 'temp_$time.$extension'));
await tempFile.writeAsString(content);
c.complete(tempFile);
return c.future;

View file

@ -21,6 +21,7 @@ class CommandConstant {
class _CommandConstantBase {
String get installPath {
var userPath = Platform.environment['HOME'];
return '';
}
@ -32,12 +33,13 @@ class _CommandConstantBase {
class _CommandConstantOSX extends _CommandConstantBase {
@override
String get installPath {
return '';
var userPath = Platform.environment['HOME'];
return '$userPath/Applications/${CLI.serviceName}/';
}
@override
String get installFilePath {
return '';
return '$installPath${CLI.serviceName}';
}
}

View file

@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'package:dart_framework/utils/os_startup.dart';
import 'package:dart_framework/utils/system_util.dart';
import 'package:oto_cli/cli/cli.dart';
import 'package:oto_cli/cli/commands/command_base.dart';
import 'package:oto_cli/cli/commands/command_const.dart';
@ -13,7 +14,6 @@ class CommandInstall extends CommandBase {
@override
Future execute(List<String> parameters) async {
var c = Completer();
var label = CLI.serviceName;
if (!await OSStartup.isRegistedStartup(label)) {
var installPath = CommandConstant.OS!.installPath;
@ -39,7 +39,7 @@ class CommandInstall extends CommandBase {
printOut('Installation failed because it is already installed.',
PrintType.error);
}
return c.future;
return simpleFuture;
}
@override

View file

@ -28,18 +28,76 @@ class RegistPath {
}
}
/// ************* MAC ***************
class _RegistPathOSX extends RegistPath {
String getTargetPath(String targetPath) {
return 'export PATH=\${PATH}:$targetPath';
}
String get zprofile {
var userPath = Platform.environment['HOME'];
return '$userPath/.zprofile';
}
String get bprofile {
var userPath = Platform.environment['HOME'];
return '$userPath/.bash_profile';
}
@override
Future add(String path) async {
return null;
await addProfile(zprofile, path);
await addProfile(bprofile, path);
await ProcessExecutor.run(
StringBuffer('source $zprofile && source $bprofile'));
return simpleFuture;
}
Future addProfile(String profilePath, String targetPath) async {
var file = File(profilePath);
var contents = '';
if (file.existsSync()) {
contents = await file.readAsString();
} else {
file.createSync();
}
if (contents.lastIndexOf('\n') != contents.length - 1) {
contents += '\n';
}
var addItem = getTargetPath(targetPath);
if (!contents.contains(addItem)) {
contents += addItem;
}
await file.writeAsString(contents, flush: true);
return simpleFuture;
}
@override
Future remove(String path) async {
return null;
await removeProfile(zprofile, path);
await removeProfile(bprofile, path);
await ProcessExecutor.run(
StringBuffer('source $zprofile && source $bprofile'));
return simpleFuture;
}
Future removeProfile(String profilePath, String targetPath) async {
var file = File(profilePath);
var contents = '';
if (file.existsSync()) {
contents = await file.readAsString();
var removeItem = getTargetPath(targetPath);
if (contents.contains(removeItem)) {
contents = contents.replaceAll(removeItem, '');
await file.writeAsString(contents, flush: true);
}
}
return simpleFuture;
}
}
/// ************* LINUX ***************
class _RegistPathLinux extends RegistPath {
@override
Future add(String path) async {
@ -52,6 +110,7 @@ class _RegistPathLinux extends RegistPath {
}
}
/// ************* WINDOWS ***************
class _RegistPathWindows extends RegistPath {
@override
Future add(String path) async {