Skip to content

Commit 2bedb12

Browse files
authored
Merge pull request #29 from UniToolsTeam/feature/improved-commandline
Feature/improved commandline
2 parents ed09579 + 565b3df commit 2bedb12

File tree

51 files changed

+718
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+718
-406
lines changed

Editor/BatchMode/BatchModeBuilder.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@ public static async void Execute()
1414
throw new Exception($"{nameof(BatchModeBuilder)}: can be run only from the BatchMode!");
1515
}
1616

17-
BatchModeParameters parameters = CommandLineParser.Parse<BatchModeParameters>(Environment.CommandLine);
17+
const string key = "--pipeline";
18+
string pipeline = string.Empty;
1819

19-
string pipelineName = parameters.Pipeline;
20+
if (!CommandLineParser.TryToParseValue(Environment.CommandLine, key, out object v))
21+
{
22+
throw new Exception($"The pipeline is not assigned from the CommandLine. Use {key} to define a pipeline for execution.");
23+
}
24+
25+
pipeline = v.ToString();
2026

21-
if (Find(pipelineName) != null)
27+
if (Find(pipeline) != null)
2228
{
23-
await RunBuildPipeline(pipelineName);
29+
await RunBuildPipeline(pipeline);
2430
}
2531
else
2632
{
27-
throw new Exception($"Failed to find a pipeline with name {pipelineName}!");
33+
throw new Exception($"Failed to find a pipeline with name {pipeline}!");
2834
}
2935
}
3036

Editor/BatchMode/BatchModeParameters.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

Editor/BatchMode/BatchModeParameters.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Editor/BatchMode/CommandLineParameterAttribute.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

Editor/BatchMode/CommandLineParameterAttribute.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Editor/BatchMode/CommandLineParser.cs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,29 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
3-
using System.Reflection;
4-
using UnityEngine;
5-
61
namespace UniTools.Build
72
{
83
public static class CommandLineParser
94
{
105
private const string KeyStart = "-";
116

12-
public static T Parse<T>(string commandLine) where T : class, new()
7+
public static bool TryToParseValue(string commandLine, string key, out object val)
138
{
14-
T t = new T();
15-
16-
Dictionary<string, object> parameters = new Dictionary<string, object>();
179
string[] args = commandLine.Split(' ');
1810
for (int i = 0; i < args.Length; i++)
1911
{
20-
if (IsKey(args[i]))
12+
if (IsKey(args[i]) && args[i].Equals(key))
2113
{
22-
string key = args[i];
23-
object val = null;
2414
int next = i + 1;
2515
if (next < args.Length && !IsKey(args[next]))
2616
{
2717
val = args[next];
28-
}
2918

30-
key = key.Replace(KeyStart, string.Empty).ToLower();
31-
if (parameters.ContainsKey(key))
32-
{
33-
Debug.LogWarning($"{nameof(CommandLineParser)}: duplication of the parameter {key}");
34-
parameters[key] = val;
35-
}
36-
else
37-
{
38-
parameters.Add(key, val);
19+
return true;
3920
}
4021
}
4122
}
4223

43-
FieldInfo[] fields =
44-
t.GetType()
45-
.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
46-
.Where(f => f.IsDefined(typeof(CommandLineParameterAttribute), false))
47-
.ToArray()
48-
;
49-
50-
foreach (FieldInfo info in fields)
51-
{
52-
string fieldName = info.Name.ToLower();
53-
if (parameters.TryGetValue(fieldName, out object p))
54-
{
55-
info.SetValue(t, p ?? true);
56-
}
57-
}
24+
val = null;
5825

59-
return t;
26+
return false;
6027
}
6128

6229
private static bool IsKey(string param)

Editor/Core/CustomEditors/BuildPipelinePresenter.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

Editor/Core/CustomEditors/BuildPipelinesProjectSettingsProvider.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace UniTools.Build
2+
{
3+
public abstract class BuildParameterPresenter
4+
{
5+
6+
public abstract string CliKey { get; }
7+
8+
public abstract void Draw(bool duplicated);
9+
}
10+
}

Editor/Core/Parameters/BuildParameterPresenter.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)