Skip to content

Commit 93fee3e

Browse files
authored
Merge pull request #10 from ktos/pull-default-version
Use current project version as default in `darkrift pull`
2 parents 52f8095 + 7fa8744 commit 93fee3e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Program.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class GetOptions
5757
[Verb("pull", HelpText = "Pulls the specified version of DarkRift locally.")]
5858
class PullOptions
5959
{
60-
[Value(0, Required = true)]
60+
[Value(0, Required = false)]
6161
public String Version { get; set; }
6262

6363
[Option('p', "pro", Default = false, HelpText = "Use the pro version.")]
@@ -196,6 +196,30 @@ private static int Get(GetOptions opts)
196196

197197
private static int Pull(PullOptions opts)
198198
{
199+
if (string.IsNullOrEmpty(opts.Version))
200+
{
201+
// if version info was omitted, overwrite any parameters with current project settings
202+
if (Project.IsCurrentDirectoryAProject())
203+
{
204+
var project = Project.Load();
205+
206+
opts.Version = project.Runtime.Version;
207+
opts.Platform = project.Runtime.Platform;
208+
opts.Tier = project.Runtime.Tier == ServerTier.Pro;
209+
}
210+
else
211+
{
212+
Console.Error.WriteLine(Output.Red($"You can perform this command only in a project directory."));
213+
return 2;
214+
}
215+
}
216+
217+
// if version provided is "latest", it is being replaced with currently most recent one
218+
if (opts.Version == "latest")
219+
{
220+
opts.Version = VersionManager.GetLatestDarkRiftVersion();
221+
}
222+
199223
string path = VersionManager.GetInstallationPath(opts.Version, opts.Tier ? ServerTier.Pro : ServerTier.Free, opts.Platform);
200224

201225
if (path == null)

Project.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,15 @@ public void Save()
5757
ser.WriteObject(writer, this);
5858
}
5959
}
60+
61+
/// <summary>
62+
/// Returns if the current directory is the directory where project is located
63+
/// by checking existence of Project.xml file.
64+
/// </summary>
65+
/// <returns>Returns if the current directory is a project directory</returns>
66+
public static bool IsCurrentDirectoryAProject()
67+
{
68+
return File.Exists("Project.xml");
69+
}
6070
}
6171
}

0 commit comments

Comments
 (0)