WshNamed, WshUnnamed and default properties

This commit is contained in:
Zev Spitz
2018-05-11 04:02:23 +02:00
parent 2341c608c1
commit 4eacdfac29
2 changed files with 70 additions and 3 deletions
+40 -2
View File
@@ -159,6 +159,23 @@ declare namespace IWshRuntimeLibrary {
AtEndOfStream: boolean;
}
/** Provides access to the entire collection of command-line parameters, in the order in which they were originally entered. */
interface WshArguments {
Count(): number;
Item(index: number): string;
Length: number;
Named: WshNamed;
/**
* When you run the **ShowUsage** method, a help screen (referred to as the usage) appears and displays details about the script's command line options.
* This information comes from the runtime section of the `*.WSF` file. Everything written between the `<runtime>` and `</runtime>` tags is pieced together
* to produce what is called a "usage statement." The usage statement tells the user how to use the script.
*/
ShowUsage(): void;
Unnamed: WshUnnamed;
(index: number): string;
}
/** Generic Collection Object */
interface WshCollection {
Count(): number;
@@ -171,7 +188,7 @@ declare namespace IWshRuntimeLibrary {
interface WshEnvironment {
Count(): number;
Item(Name: string): string;
readonly length: number;
readonly Length: number;
Remove(Name: string): void;
(Name: string): string;
}
@@ -189,6 +206,19 @@ declare namespace IWshRuntimeLibrary {
Terminate(): void;
}
/**
* Provides access to the named command-line arguments
*
* Note that enumerating over this object returns the **names** of the arguments, not the values
*/
interface WshNamed {
Count(): number;
Exists(Key: string): boolean;
Item(name: string): string;
Length: number;
(name: string): string;
}
/** Network Object */
class WshNetwork {
private 'IWshRuntimeLibrary.WshNetwork_typekey': WshNetwork;
@@ -388,6 +418,14 @@ declare namespace IWshRuntimeLibrary {
WorkingDirectory: string;
}
/** Provides access to the unnamed command-line arguments */
interface WshUnnamed {
Count(): number;
Item(index: number): string;
Length: number;
(index: number): string;
}
/** URLShortcut Object */
class WshURLShortcut {
private 'IWshRuntimeLibrary.WshURLShortcut_typekey': WshURLShortcut;
@@ -417,7 +455,7 @@ declare var WScript: {
* Can be accessed only while using CScript.exe.
*/
StdOut: IWshRuntimeLibrary.TextStreamWriter;
Arguments: { length: number; Item(n: number): string; };
Arguments: IWshRuntimeLibrary.WshArguments;
/**
* The full path of the currently running script.
@@ -1 +1,30 @@
WScript.Echo(WScript.Arguments.length);
const collectionToArray = <T>(col: { Item(key: any): T }): T[] => {
const results: T[] = [];
const enumerator = new Enumerator<T>(col);
enumerator.moveFirst();
while (!enumerator.atEnd()) {
results.push(enumerator.item());
enumerator.moveNext();
}
return results;
};
// Show all of the arguments.
WScript.Echo(`${WScript.Arguments.Length} arguments`);
for (const arg of collectionToArray(WScript.Arguments)) {
WScript.Echo(` ${arg}`);
}
// Show the unnamed arguments.
WScript.Echo(`${WScript.Arguments.Unnamed.Length} unnamed arguments`);
for (const unnamed of collectionToArray(WScript.Arguments.Unnamed)) {
WScript.Echo(` ${unnamed}`);
}
// Show the named arguments.
WScript.Echo(`${WScript.Arguments.Named.Length} named arguments`);
for (const key of collectionToArray(WScript.Arguments.Named)) {
WScript.Echo(` ${key}=${WScript.Arguments.Named(key)}`);
}