forked from akiver/cs-demo-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseCommand.cs
63 lines (55 loc) · 1.44 KB
/
BaseCommand.cs
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
using System;
using System.IO;
using System.Threading.Tasks;
namespace CLI
{
internal abstract class BaseCommand
{
private readonly string _name;
private readonly string _description;
public abstract Task Run(string[] args);
public abstract void PrintHelp();
protected BaseCommand(string name, string description = "")
{
_name = name;
_description = description;
}
public string GetName()
{
return _name;
}
public string GetDescription()
{
return _description;
}
public void ParseArgs(string[] args)
{
foreach (string arg in args)
{
if (arg == "--help")
{
PrintHelp();
Environment.Exit(0);
}
}
}
protected bool IsCurrentDirectoryWritable()
{
return IsDirectoryWritable(Directory.GetCurrentDirectory());
}
protected bool IsDirectoryWritable(string directoryPath)
{
try
{
using (FileStream fs = File.Create(Path.Combine(directoryPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose))
{
}
return true;
}
catch
{
return false;
}
}
}
}