Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
fixes cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed Jul 8, 2019
1 parent 968ad07 commit 727d3a1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 52 deletions.
25 changes: 7 additions & 18 deletions Rune/cmd/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
using Ancient.ProjectSystem;
using cli;
using etc;
using Internal;

public class BuildCommand
public class BuildCommand : WithProject
{
public AncientProject project { get; set; }


public static int Run(string[] args)
{
var app = new CommandLineApplication
Expand Down Expand Up @@ -44,17 +42,8 @@ public static int Run(string[] args)
public int Execute(bool isTemp)
{
var directory = Directory.GetCurrentDirectory();
var projectFiles = Directory.GetFiles(directory, "*.rune.json");

if (projectFiles.Length == 0)
{
Console.WriteLine($"{":cd:".Emoji()} {"Couldn't".Color(Color.Red)} find a project to run. {"Ensure".Nier(0)} a project exists in '{directory}'.");
if (!Validate(directory))
return 1;
}

var p = projectFiles.Single();

project = AncientProject.Open(new FileInfo(p));

var ancient_home = Environment.GetEnvironmentVariable("ANCIENT_HOME", EnvironmentVariableTarget.User);

Expand All @@ -77,10 +66,10 @@ public int Execute(bool isTemp)

if (isTemp)
outputDir = "obj";

argBuilder.Add($"-o ./{outputDir}/{project.name}");
if(project.extension != null)
argBuilder.Add($"-e {project.extension}");
var Project = AncientProject.FromLocal();
argBuilder.Add($"-o ./{outputDir}/{Project.Name}");
if(Project.Extension != null)
argBuilder.Add($"-e {Project.Extension}");
argBuilder.Add($"-s \"{files.First()}\"");

var external = new ExternalTools(acc_bin, string.Join(" ", argBuilder));
Expand Down
1 change: 1 addition & 0 deletions Rune/cmd/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private static string BuildUsageText()
builder.AppendLine($" {"install".Color(Color.CornflowerBlue)} {"Install device package from ancient registry".Color(Color.DarkKhaki)}");
builder.AppendLine($" {"clear".Color(Color.CornflowerBlue)} {"Clearing deps in current project".Color(Color.DarkKhaki)}");
builder.AppendLine($" {"build".Color(Color.CornflowerBlue)} {"Builds a Ancient project".Color(Color.DarkKhaki)}");
builder.AppendLine($" {"restore".Color(Color.CornflowerBlue)} {"Restore packages from current project".Color(Color.DarkKhaki)}");
builder.AppendLine($" {"run".Color(Color.CornflowerBlue)} {"Immediately executes a script from Ancient project".Color(Color.DarkKhaki)}");
builder.AppendLine($" {"vm".Color(Color.CornflowerBlue)} {"Immediately build and execute project in Ancient VM".Color(Color.DarkKhaki)}");
builder.AppendLine();
Expand Down
18 changes: 15 additions & 3 deletions Rune/cmd/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
using Ancient.ProjectSystem;
using cli;
using etc;
using Internal;

public class InstallCommand
public class InstallCommand : WithProject
{
public static int Run(string[] args)
{
Expand All @@ -23,7 +24,14 @@ public static int Run(string[] args)
var package = app.Argument("<package>", "package name");
var registry = app.Option("--registry <url>", "registry url", CommandOptionType.SingleValue);
var cmd = new InstallCommand();
app.OnExecute(() => cmd.Execute(package.Value, registry));
var restore = new RestoreCommand();
app.OnExecute(() =>
{
var result = cmd.Execute(package.Value, registry);
if (result != 0)
return result;
return restore.Execute(registry);
});

try
{
Expand All @@ -41,6 +49,9 @@ public int Execute(string package, CommandOption registryOption)
var registry = registryOption.HasValue() ? registryOption.Value() : "github+https://github.com/ancientproject";
var dir = Directory.GetCurrentDirectory();

if (!Validate(dir))
return 1;

if (Indexer.FromLocal().UseLock().Exist(package))
{
Console.WriteLine($"{":page_with_curl:".Emoji()} '{package}' is already {"found".Nier(0).Color(Color.Red)} in project.");
Expand All @@ -64,11 +75,12 @@ public int Execute(string package, CommandOption registryOption)
Indexer.FromLocal()
.UseLock()
.SaveDep(asm, bytes, registry);
AncientProject.FromLocal().AddDep(package, asm.GetName().Version.ToString(), DepVersionKind.Fixed);
Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' save to deps is {"success".Nier(0).Color(Color.GreenYellow)}.");
}
catch (Exception e)
{
Console.WriteLine(e.Message.Color(Color.Red));
Console.WriteLine(e.ToString().Color(Color.Red));
return 2;
}
return 0;
Expand Down
28 changes: 28 additions & 0 deletions Rune/cmd/Internal/WithProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace rune.cmd.Internal
{
using System;
using System.Drawing;
using System.IO;
using Ancient.ProjectSystem;
using etc;

public abstract class WithProject
{
public bool Validate(string directory)
{
var projectFiles = Directory.GetFiles(directory, "*.rune.json");

if (projectFiles.Length == 0)
{
Console.WriteLine($"{":fried_shrimp:".Emoji()} {"Couldn't".Nier().Color(Color.Red)} find a project to run. Ensure a project exists in {directory}.");
return false;
}
if (projectFiles.Length > 1)
{
Console.WriteLine($"{":fried_shrimp:".Emoji()} {"Specify".Nier().Color(Color.Red)} which project file to use because this folder contains more than one project file..");
return false;
}
return true;
}
}
}
2 changes: 1 addition & 1 deletion Rune/cmd/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private int CreateEmptyProject()
var author = new ValueView<string>($"[4/4] {":skull:".Emoji()} Project Author:").WithDefault("").Read();
var dir = Directory.GetCurrentDirectory();

var proj = new AncientProject
var proj = new AncientProjectFile
{
name = projectName,
version = version,
Expand Down
19 changes: 5 additions & 14 deletions Rune/cmd/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
using Ancient.ProjectSystem;
using cli;
using etc;
using Internal;

public class RunCommand
public class RunCommand : WithProject
{
public static int Run(string[] args)
{
Expand Down Expand Up @@ -41,19 +42,9 @@ public static int Run(string[] args)
public int Execute(string value)
{
var directory = Directory.GetCurrentDirectory();
var projectFiles = Directory.GetFiles(directory, "*.rune.json");

if (projectFiles.Length == 0)
{
throw new InvalidOperationException(
$"Couldn't find a project to run. Ensure a project exists in {directory}.");
}

var project = projectFiles.Single();

var rune = AncientProject.Open(new FileInfo(project));

var script = rune.scripts.FirstOrDefault(x => x.Key.Equals(value, StringComparison.InvariantCultureIgnoreCase)).Value;
if (!Validate(directory))
return 1;
var script = AncientProject.FromLocal().scripts.FirstOrDefault(x => x.Key.Equals(value, StringComparison.InvariantCultureIgnoreCase)).Value;

if(script is null)
throw new InvalidOperationException($"Command '{value}' not found.");
Expand Down
22 changes: 6 additions & 16 deletions Rune/cmd/VMCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
using System.Drawing;
using System.IO;
using System.Linq;
using Ancient.ProjectSystem;
using cli;
using etc;
using Internal;

public class VMCommand
public class VMCommand : WithProject
{
public AncientProject project { get; set; }
public static int Run(string[] args)
{
var app = new CommandLineApplication
Expand Down Expand Up @@ -46,18 +45,9 @@ public static int Run(string[] args)

internal int Execute(CommandOption isDebug, CommandOption keepMemory, CommandOption fastWrite)
{
var directory = Directory.GetCurrentDirectory();
var projectFiles = Directory.GetFiles(directory, "*.rune.json");

if (projectFiles.Length == 0)
{
throw new InvalidOperationException(
$"Couldn't find a project to run. Ensure a project exists in {directory}.");
}

var p = projectFiles.Single();

project = AncientProject.Open(new FileInfo(p));
var dir = Directory.GetCurrentDirectory();
if (!Validate(dir))
return 1;

var ancient_home = Environment.GetEnvironmentVariable("ANCIENT_HOME", EnvironmentVariableTarget.User);

Expand Down Expand Up @@ -86,7 +76,7 @@ internal int Execute(CommandOption isDebug, CommandOption keepMemory, CommandOpt
.WithEnv("VM_KEEP_MEMORY", keepMemory.BoolValue.HasValue)
.WithEnv("VM_MEM_FAST_WRITE", fastWrite.BoolValue.HasValue)
.WithEnv("CLI", true)
.WithEnv("CLI_WORK_PATH", directory)
.WithEnv("CLI_WORK_PATH", dir)

.Start()
.Wait().ExitCode();
Expand Down

0 comments on commit 727d3a1

Please sign in to comment.