-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListOptions.cs
More file actions
115 lines (109 loc) · 4.43 KB
/
Copy pathListOptions.cs
File metadata and controls
115 lines (109 loc) · 4.43 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
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CommandLine;
using CommandLine.Text;
namespace nyoka_Client
{
[Verb("list", HelpText = "List resources in local files.")]
public class ListOptions
{
[Option("type", HelpText = "Get resource for this type.")]
public string resource { get; set; }
public Constants.ResourceType? resourceType;
//public ListOptions(List<string> actionArgs)
// {
// if (actionArgs.Count > 1)
// {
// Logger.logError($"list action takes one optional argument: resource type. Usage:");
// lstResources(resourceType);
// //successful = false;
// return;
// }
// if (actionArgs.Count == 1)
// {
// string resourceTypeStr = actionArgs[0];
// try
// {
// resourceType = ParseUtils.parseResourceType(resourceTypeStr);
// }
// catch (ParseUtils.ArgumentProcessException ex)
// {
// Logger.logError($"Error: {ex.Message}");
// // return 0;
// }
// }
// //return 1;
// }
public static int ListResources(Constants.ResourceType? listType, List<string> actionArgs)
{
if (actionArgs.Count > 1)
{
string resourceTypeStr = actionArgs[0];
Logger.logError($"list action takes one optional argument: resource type. Usage:");
listType = ParseUtils.parseResourceType(resourceTypeStr);
lstResources(listType);
}
if (actionArgs.Count == 1)
{
try
{
lstResources(listType);
}
catch (ParseUtils.ArgumentProcessException ex)
{
Logger.logError($"Error: {ex.Message}");
return 0;
}
}
return 1;
}
public static void lstResources(Constants.ResourceType? listType)
{
try
{
if (!ResourceTypes.hasNecessaryDirs())
{
Logger.logError($"Missing some or all resource directories in current directory. Try running {Constants.APPLICATION_ALIAS} init?");
return;
}
PrintTable table = new PrintTable {
{Constants.HeaderStringType, 6},
{Constants.HeaderStringNameOfResource, 21},
{Constants.HeaderStringVersion, 16},
{Constants.HeaderStringFileSize, 11},
};
List<Constants.ResourceType> resourcesToList = listType.HasValue ?
new List<Constants.ResourceType> { listType.Value } :
new List<Constants.ResourceType> { Constants.ResourceType.Code,
Constants.ResourceType.Data, Constants.ResourceType.Model };
foreach (Constants.ResourceType resourceType in resourcesToList)
{
foreach (string resourceName in ResourceTypes.resourceNames(resourceType))
{
string version;
if (ResourceTypes.resourceVersionFileExists(resourceType, resourceName))
{
version = ResourceTypes.getResourceVersion(resourceType, resourceName);
}
else
{
version = "Unknown version";
}
long fileSize = ResourceTypes.getResourceSize(resourceType, resourceName);
table.addRow(
PrintTable.doFormat(resourceType.ToString()),
PrintTable.doFormat(resourceName),
PrintTable.doFormat(version),
PrintTable.doFormat(ResourceTypes.bytesToString(fileSize))
);
}
}
Logger.logTable(table);
}
catch
{ }
}
}
}