コード例 #1
0
        public static EnvironmentParameters InitializeEnvironment(params string[] args)
        {
            if (!args.Any())
            {
                Console.WriteLine(EnvironmentParameters.GetUsageInfo());
                Environment.Exit(0);
            }

            var commandParser  = new CommandLineArgumentsParser(args);
            var inputMethod    = commandParser.GetEnumParameter <InputMethod>(parameterName: "-inputMethod", defaultValue: InputMethod.Arguments);
            var environment    = commandParser.GetEnumParameter <ARMEnvironment>(parameterName: "-env", defaultValue: ARMEnvironment.Unknown);
            var outputMethod   = commandParser.GetEnumParameter <OutputMethod>(parameterName: "-outputMethod", defaultValue: OutputMethod.Unknown);
            var subscriptionId = commandParser.GetStringParameter(parameterName: "-subscriptionId", defaultValue: string.Empty);
            var userId         = commandParser.GetStringParameter(parameterName: "-userId", defaultValue: string.Empty);

            if (inputMethod == InputMethod.Interactive)
            {
                if (environment == ARMEnvironment.Unknown)
                {
                    environment = OutputHelpers.PromptForEnumInput(
                        prompt: "Choose environment by index: ",
                        defaultValue: ARMEnvironment.Production,
                        options: new ARMEnvironment[] { ARMEnvironment.Next, ARMEnvironment.Current, ARMEnvironment.Dogfood, ARMEnvironment.Production });
                }

                if (outputMethod == OutputMethod.Unknown)
                {
                    outputMethod = OutputHelpers.PromptForEnumInput(
                        prompt: "Choose output method by index: ",
                        defaultValue: OutputMethod.TempFile,
                        options: new OutputMethod[] { OutputMethod.Print, OutputMethod.TempFile, OutputMethod.Clipboard });
                }

                if (string.IsNullOrEmpty(subscriptionId))
                {
                    subscriptionId = OutputHelpers.PromptForStringInput("Enter subscription Id (Optional): ");
                }

                if (string.IsNullOrEmpty(userId))
                {
                    userId = OutputHelpers.PromptForStringInput("Enter user email (Optional): ");
                }
            }

            if (environment == ARMEnvironment.Unknown)
            {
                throw new ArgumentException("-env parameter must be specified. Valid values: Next, Current, Dogfood, Production");
            }

            return(new EnvironmentParameters(
                       environment: environment,
                       outputMethod: outputMethod,
                       subscriptionId: subscriptionId,
                       userId: userId));
        }
コード例 #2
0
ファイル: OutputHelpers.cs プロジェクト: sbanina/ARMTokenTool
        public static void OutputToken(OutputMethod outputMethod, string token)
        {
            switch (outputMethod)
            {
            case OutputMethod.Clipboard:
                OutputHelpers.CopyToClipboard(text: token);
                return;

            case OutputMethod.TempFile:
                OutputHelpers.WriteToTempFile(text: token);
                return;

            case OutputMethod.Print:
            default:
                Console.WriteLine(token);
                return;
            }
        }