forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandFactory.cs
More file actions
106 lines (87 loc) · 3.71 KB
/
CommandFactory.cs
File metadata and controls
106 lines (87 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System.IO;
namespace ScriptCs.Command
{
public class CommandFactory
{
private readonly ScriptServiceRoot _scriptServiceRoot;
public CommandFactory(ScriptServiceRoot scriptServiceRoot)
{
_scriptServiceRoot = scriptServiceRoot;
}
public ICommand CreateCommand(ScriptCsArgs args)
{
if (args.Help)
{
return new ShowUsageCommand(_scriptServiceRoot.Logger, isValid: true);
}
if (args.Repl)
{
var replCommand = new ExecuteReplCommand(
_scriptServiceRoot.FileSystem, _scriptServiceRoot.ScriptPackResolver,
_scriptServiceRoot.Engine, _scriptServiceRoot.FilePreProcessor, _scriptServiceRoot.Logger, _scriptServiceRoot.Console);
return replCommand;
}
if (args.ScriptName != null)
{
var executeCommand = new ExecuteScriptCommand(
args.ScriptName,
_scriptServiceRoot.FileSystem,
_scriptServiceRoot.Executor,
_scriptServiceRoot.ScriptPackResolver,
_scriptServiceRoot.Logger);
if (args.Restore)
{
var restoreCommand = new RestoreCommand(
args.ScriptName,
_scriptServiceRoot.FileSystem,
_scriptServiceRoot.PackageAssemblyResolver,
_scriptServiceRoot.Logger);
return new CompositeCommand(restoreCommand, executeCommand);
}
return executeCommand;
}
if (args.Install != null)
{
var installCommand = new InstallCommand(
args.Install,
args.AllowPreRelease,
_scriptServiceRoot.FileSystem,
_scriptServiceRoot.PackageAssemblyResolver,
_scriptServiceRoot.PackageInstaller,
_scriptServiceRoot.Logger);
var restoreCommand = new RestoreCommand(
args.Install,
_scriptServiceRoot.FileSystem,
_scriptServiceRoot.PackageAssemblyResolver,
_scriptServiceRoot.Logger);
var currentDirectory = _scriptServiceRoot.FileSystem.CurrentDirectory;
var packageFile = Path.Combine(currentDirectory, Constants.PackagesFile);
if (!_scriptServiceRoot.FileSystem.FileExists(packageFile))
{
var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver);
return new CompositeCommand(installCommand, restoreCommand, saveCommand);
}
return new CompositeCommand(installCommand, restoreCommand);
}
if (args.Clean)
{
var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver);
var cleanCommand = new CleanCommand(
args.ScriptName,
_scriptServiceRoot.FileSystem,
_scriptServiceRoot.PackageAssemblyResolver,
_scriptServiceRoot.Logger);
return new CompositeCommand(saveCommand, cleanCommand);
}
if (args.Save)
{
return new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver);
}
if (args.Version)
{
return new VersionCommand();
}
return new ShowUsageCommand(_scriptServiceRoot.Logger, isValid: false);
}
}
}