Skip to content

Commit

Permalink
Changing how version control works.
Browse files Browse the repository at this point in the history
  • Loading branch information
DrRetro2033 committed Sep 23, 2024
1 parent ca3e2c6 commit 4e5b87c
Show file tree
Hide file tree
Showing 9 changed files with 1,952 additions and 857 deletions.
121 changes: 0 additions & 121 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import 'dart:io';
import 'dart:convert';
// import 'package:ansix/ansix.dart';
import "package:args/command_runner.dart";
import 'package:cli_spin/cli_spin.dart';
import 'file_pattern.dart';
import 'extensions.dart';
import "version_control/constellation.dart";

/// # `void` main(List<String> arguments)
/// ## Main entry point.
Expand All @@ -21,132 +19,13 @@ Future<dynamic> main(List<String> arguments) async {
abbr: "a",
defaultsTo: Directory.current.path,
);
runner.addCommand(ConstellationCommands());
runner.addCommand(PatternCommands());
currentPath = runner.argParser.parse(arguments)["app-path"];
if (arguments.isNotEmpty) {
return await runner.run(arguments);
}
}

class ConstellationCommands extends Command {
@override
String get name => "const";
@override
String get description => "Commands for Constellations.";

ConstellationCommands() {
addSubcommand(CreateConstellationCommand());
addSubcommand(ShowMapConstellationCommand());
addSubcommand(CheckForDifferencesCommand());
addSubcommand(ConstellationJumpToCommand());
addSubcommand(ConstellationBranchCommand());
}
}

class CreateConstellationCommand extends Command {
@override
String get description =>
"Creates a new constellation at a given, or current, path.";

@override
String get name => "create";

CreateConstellationCommand() {
argParser.addOption("path", abbr: "p", mandatory: true);
argParser.addOption("name", abbr: "n", mandatory: true);
}

@override
void run() {
Constellation(argResults?["path"], name: argResults?["name"]);
}
}

class ShowMapConstellationCommand extends Command {
@override
String get description => "Shows the map of a constellation.";

@override
String get name => "map";

ShowMapConstellationCommand() {
argParser.addOption("path", abbr: "p", mandatory: true);
}

@override
void run() {
Constellation(argResults?["path"]).starmap.showMap();
}
}

class CheckForDifferencesCommand extends Command {
@override
String get description =>
"Checks for differences between a star and the current file.";

@override
String get name => "check";

CheckForDifferencesCommand() {
argParser.addOption("path", abbr: "p", mandatory: true);
argParser.addOption("star", abbr: "s");
}

@override
Future<bool> run() async {
Constellation constellation = Constellation(argResults?["path"]);
final spinner = CliSpin(
text:
"Checking for differences between current directory and provided star...")
.start();
bool result = constellation.checkForDifferences(argResults?["star"]);
if (!result) {
spinner.success("No differences found.");
} else {
spinner.fail("Differences found.");
}
return result;
}
}

class ConstellationJumpToCommand extends Command {
@override
String get description =>
"Jumps to a star in the constellation. Must call extract if you want the star to be extracted.";

@override
String get name => "jump";

ConstellationJumpToCommand() {
argParser.addOption("path", abbr: "p", mandatory: true);
argParser.addOption("star", abbr: "s", mandatory: true);
}

@override
void run() {
Constellation(argResults?["path"]).starmap[argResults?["star"]];
}
}

class ConstellationBranchCommand extends Command {
@override
String get description =>
"Creates a new branch in the constellation from the current star.";
@override
String get name => "branch";

ConstellationBranchCommand() {
argParser.addOption("path", abbr: "p", mandatory: true);
argParser.addOption("name", abbr: "n", mandatory: true);
}

@override
void run() {
Constellation(argResults?["path"]).branch(argResults?["name"]);
}
}

class PatternCommands extends Command {
@override
String get name => "pattern";
Expand Down
38 changes: 38 additions & 0 deletions bin/starmap.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:isar/isar.dart';

part 'starmap.g.dart';

@collection
class User {
Id? id;
late String name;

@Backlink(to: 'user')
final stars = IsarLinks<Star>();
}

@collection
class File {
Id? id;

@IndexType.hash
late String filename;

@Backlink(to: 'file')
final stars = IsarLinks<Star>();
}

@collection
class Star {
Id? id;

late String name;
late List<byte> data;
final file = IsarLink<File>();
final user = IsarLink<User>();

final next = IsarLinks<Star>();

@Backlink(to: 'next')
final prev = IsarLinks<Star>();
}
Loading

0 comments on commit 4e5b87c

Please sign in to comment.