Skip to content

Commit 2e13127

Browse files
committed
Merge pull request #1592 from johanste/clu
Allow explicit command aliasing for the CLU CLI
2 parents 61e9901 + b320357 commit 2e13127

19 files changed

+308
-858
lines changed

src/CLU/Microsoft.CLU.Common/CLUEnvironment.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public static class CLUEnvironment
2222
/// </summary>
2323
private static string PackagesRootPathEnvVaribleName = "PackagesRootPath";
2424

25-
/// <summary>
26-
/// Name of the environment variable holding working directory root path.
27-
/// </summary>
28-
private static string WorkDirsRootPathEnvVaribleName = "WorkDirsRootPath";
29-
3025
/// <summary>
3126
/// Set the root paths.
3227
/// </summary>
@@ -41,7 +36,6 @@ public static void SetRootPaths(string cluRootPath)
4136
rootPathPrefix = "/";
4237
}
4338
SetEnvironmentVariable(PackagesRootPathEnvVaribleName, rootPathPrefix + Path.Combine(cluRootPath, Common.Constants.PackageFolderName));
44-
SetEnvironmentVariable(WorkDirsRootPathEnvVaribleName, Path.Combine(cluRootPath, Common.Constants.WorkFolderName));
4539
}
4640

4741
/// <summary>

src/CLU/Microsoft.CLU.Common/CmdletIndex.cs

Lines changed: 8 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -24,77 +24,28 @@ namespace Microsoft.CLU
2424
///
2525
/// [_indexes]
2626
/// |
27-
/// ===========================================
28-
/// | | |
29-
/// | | |
30-
/// [vm] [network] _cmdlet.idx
31-
/// | |
32-
/// ================== [virtual]
33-
/// | | | |
34-
/// [create] [delete] _cmdlet.idx ==================
35-
/// | | | | |
36-
/// _cmdlet.idx _cmdlet.idx [create] [delete] _cmdlet.idx
37-
/// | |
38-
/// _cmdlet.idx _cmdlet.idx
39-
///
27+
/// _cmdlet.idx
28+
///
4029
/// The notation [abc] represents a directory, where 'abc' is the directory name.
4130
///
4231
/// [_indexes] represents the root directory "_indexes".
43-
/// There is a directory corrosponding to each discriminator of commands, each such directory contains a
44-
/// file named _cmdlet.idx which is the index for commands this discriminator participate.
45-
/// For example _cmdlet.idx under [virtual] diretory will contains index for following commands
46-
/// vm network create
47-
/// vm network delete
48-
/// _cmdlet.idx under [virtual]/[create] index
49-
/// vm network create
5032
/// </summary>
5133
internal class CmdletIndex
5234
{
53-
/// <summary>
54-
/// Name of the index.
55-
/// </summary>
56-
public string Name { get; set; }
57-
5835
/// <summary>
5936
/// The index-entries. These entries will be serialized to/from the file _cmdlet.idx.
6037
/// </summary>
6138
public ConfigurationDictionary Entries { get; set; } = new ConfigurationDictionary();
6239

63-
/// <summary>
64-
/// Child indicies.
65-
/// </summary>
66-
public Dictionary<string, CmdletIndex> Children { get; set; } = new Dictionary<string, CmdletIndex>();
67-
68-
/// <summary>
69-
/// Index a command identified by the given command discriminators.
70-
/// </summary>
71-
/// <param name="keys">The command discriminator list from which key needs to be derived</param>
72-
/// <param name="value">The value</param>
73-
public void Add(List<string> keys, string value)
74-
{
75-
Add(keys, 0, value);
76-
}
7740

7841
/// <summary>
7942
/// Recursively index each discriminator in the given command keys.
8043
/// </summary>
8144
/// <param name="keys">The command discriminator list from which key needs to be derived</param>
82-
/// <param name="level">The discriminator level</param>
8345
/// <param name="value">The value</param>
84-
private void Add(List<string> keys, int level, string value)
46+
private void Add(List<string> keys, string value)
8547
{
8648
Entries.Add(string.Join(Constants.CmdletIndexWordSeparator, keys), value);
87-
if (level < keys.Count)
88-
{
89-
CmdletIndex childIndex;
90-
if (!Children.TryGetValue(keys[level], out childIndex))
91-
{
92-
childIndex = new CmdletIndex { Name = keys[level] };
93-
Children.Add(keys[level], childIndex);
94-
}
95-
96-
childIndex.Add(keys, level + 1, value);
97-
}
9849
}
9950

10051
/// <summary>
@@ -105,51 +56,31 @@ public void Save(string path)
10556
{
10657
Debug.Assert(!string.IsNullOrEmpty(path));
10758

108-
var fullPath = string.IsNullOrEmpty(Name) ? path : Path.Combine(path, Name);
109-
if (!Directory.Exists(fullPath))
110-
Directory.CreateDirectory(fullPath);
59+
if (!Directory.Exists(path))
60+
Directory.CreateDirectory(path);
11161

112-
var indexFilePath = Path.Combine(fullPath, Constants.CmdletsIndexFileName);
62+
var indexFilePath = Path.Combine(path, Constants.CmdletsIndexFileName);
11363
if (Entries.Count > 0)
11464
Entries.Store(indexFilePath);
115-
116-
foreach (var idx in Children.Values)
117-
{
118-
idx.Save(fullPath);
119-
}
12065
}
12166

12267
/// <summary>
12368
/// Load the index.
12469
/// </summary>
125-
/// <param name="keys">The command discriminator list identifying the index to be loaded</param>
12670
/// <param name="path">The index file path</param>
127-
/// <param name="recursive">
128-
/// True - If the index for all command discriminator in the discriminator list needs to be loaded
129-
/// False - Only the index of the root discriminator needs to be loaded</param>
13071
/// <returns></returns>
131-
public static CmdletIndex Load(IEnumerable<string> keys, string path, bool recursive)
72+
public static CmdletIndex Load(string path)
13273
{
133-
Debug.Assert(keys != null);
13474
Debug.Assert(!string.IsNullOrEmpty(path));
13575

136-
var indexName = keys.FirstOrDefault();
13776
var indexFullPath = Path.Combine(path, Constants.CmdletsIndexFileName);
13877

139-
var cmdletIndex = new CmdletIndex { Name = indexName };
78+
var cmdletIndex = new CmdletIndex();
14079
if (File.Exists(indexFullPath))
14180
{
14281
cmdletIndex.Entries = ConfigurationDictionary.Load(indexFullPath);
14382
}
14483

145-
if (recursive)
146-
{
147-
foreach (var dir in Directory.EnumerateDirectories(path))
148-
{
149-
cmdletIndex.Children.Add(indexName, Load(keys.Skip(1), Path.Combine(path, indexName), true));
150-
}
151-
}
152-
15384
return cmdletIndex;
15485
}
15586

@@ -158,9 +89,7 @@ public static CmdletIndex Load(IEnumerable<string> keys, string path, bool recur
15889
/// </summary>
15990
public void Clear()
16091
{
161-
Name = null;
16292
Entries.Clear();
163-
Children.Clear();
16493
}
16594
}
16695
}

src/CLU/Microsoft.CLU.Common/Constants.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@ public static class Constants
1616
/// </summary>
1717
public const string CLUConfigFileName = "msclu.cfg";
1818

19-
/// <summary>
20-
/// The standard name of a command index file on disk.
21-
/// </summary>
22-
internal const string StaticCommandIndex = "_index";
23-
2419
/// <summary>
2520
/// The standard name of a cmdlet index file on disk.
2621
/// </summary>
2722
internal const string CmdletsIndexFileName = "_cmdlets.idx";
2823

24+
#if PSCMDLET_HELP
2925
/// <summary>
3026
/// The standard name of a name mapping file on disk.
3127
/// </summary>
3228
internal const string NameMappingFileName = "_namemap.idx";
33-
29+
#endif
3430
/// <summary>
3531
/// The name of a package's index folder.
3632
/// </summary>
@@ -56,11 +52,6 @@ public static class Constants
5652
/// </summary>
5753
public const string PackageFolderName = "pkgs";
5854

59-
/// <summary>
60-
/// The canonical name of the root folder for all command package working directories.
61-
/// </summary>
62-
public const string WorkFolderName = "workdirs";
63-
6455
/// <summary>
6556
/// Package installation marker file name.
6657
/// </summary>

0 commit comments

Comments
 (0)