Skip to content

Commit

Permalink
Merge pull request #10 from Snapp-Embedded/feat/ssh-connection
Browse files Browse the repository at this point in the history
Create a passwordless ssh connection
  • Loading branch information
payam-zahedi authored Dec 12, 2023
2 parents aec7d3a + 8295866 commit 084362b
Show file tree
Hide file tree
Showing 12 changed files with 703 additions and 187 deletions.
21 changes: 10 additions & 11 deletions lib/command_runner/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import 'package:args/command_runner.dart';
import 'package:interact/interact.dart';
import 'package:snapp_cli/commands/devices/devices_command.dart';
import 'package:snapp_cli/commands/ssh/ssh_command.dart';
import 'package:snapp_cli/utils/common.dart';
import 'package:snapp_cli/utils/flutter_sdk.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:flutter_tools/src/base/common.dart';
Expand All @@ -25,6 +27,9 @@ class SnappCliCommandRunner extends CommandRunner<int> {

// Add the devices command to the command runner
addCommand(DevicesCommand(flutterSdkManager: flutterSdkManager));

// Create and manage SSH connections
addCommand(SshCommand(flutterSdkManager: flutterSdkManager));
}

final FlutterSdkManager flutterSdkManager;
Expand All @@ -41,7 +46,7 @@ class SnappCliCommandRunner extends CommandRunner<int> {
final isLinuxEnabled = flutterSdkManager.isLinuxEnabled;

if (!areCustomDevicesEnabled || !isLinuxEnabled) {
printSpaces();
logger.printSpaces();

logger.printStatus(
'''
Expand All @@ -50,15 +55,15 @@ This is a one time setup and will not be required again.
''',
);

printSpaces();
logger.printSpaces();

final enableConfigs = Confirm(
prompt: 'Do you want to enable them now?',
defaultValue: true, // this is optional
waitForNewLine: true, // optional and will be false by default
).interact();

printSpaces();
logger.printSpaces();

if (!enableConfigs) {
throwToolExit('''
Expand All @@ -77,7 +82,7 @@ flutter config --enable-custom-devices --enable-linux-desktop

Future<void> _enableConfigs() async {
final spinner = Spinner(
icon: '✔️',
icon: logger.successIcon,
leftPrompt: (done) => '', // prompts are optional
rightPrompt: (done) => done
? 'Configs enabled successfully!'
Expand Down Expand Up @@ -111,7 +116,7 @@ flutter config --enable-custom-devices --enable-linux-desktop
} finally {
spinner.done();

printSpaces();
logger.printSpaces();
}

if (result.exitCode != 0) {
Expand All @@ -124,10 +129,4 @@ flutter config --enable-custom-devices --enable-linux-desktop
''');
}
}

void printSpaces([int n = 2]) {
for (int i = 0; i < n; i++) {
logger.printStatus(' ');
}
}
}
46 changes: 43 additions & 3 deletions lib/commands/base_command.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// ignore_for_file: implementation_imports

import 'dart:io';

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/custom_devices/custom_devices_config.dart';
import 'package:interact/interact.dart';
import 'package:snapp_cli/utils/common.dart';
import 'package:snapp_cli/utils/flutter_sdk.dart';

abstract class BaseSnappCommand extends Command<int> {
Expand All @@ -17,10 +21,46 @@ abstract class BaseSnappCommand extends Command<int> {
flutterSdkManager.customDeviceConfig;
Logger get logger => flutterSdkManager.logger;

void printSpaces([int n = 2]) {
for (int i = 0; i < n; i++) {
logger.printStatus(' ');
(InternetAddress ip, String username) getRemoteIpAndUsername({
required String message,
String? getIpDescription,
String? getUsernameDescription,
}) {
logger.printSpaces();

logger.printStatus(message);

if (getIpDescription != null) {
logger.printStatus(getIpDescription);
logger.printSpaces();
}

final String deviceIp = Input(
prompt: 'Device IP-address:',
validator: (s) {
if (s.isValidIpAddress) {
return true;
}
throw ValidationError('Invalid IP-address. Please try again.');
},
).interact();

final ip = InternetAddress(deviceIp);

logger.printSpaces();

if (getUsernameDescription != null) {
logger.printStatus(getUsernameDescription);
logger.printSpaces();
}

final String username = Input(
prompt: 'Username:',
).interact();

logger.printSpaces();

return (ip, username);
}
}

Expand Down
Loading

0 comments on commit 084362b

Please sign in to comment.