コード例 #1
0
        private static void ConfigureTrace(ITrace trace, ISettings settings, StandardStreams streams)
        {
            if (settings.GetTracingEnabled(out string traceValue))
            {
                if (traceValue.IsTruthy()) // Trace to stderr
                {
                    trace.AddListener(streams.Error);
                }
                else if (Path.IsPathRooted(traceValue)) // Trace to a file
                {
                    try
                    {
                        Stream     stream           = File.Open(traceValue, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                        TextWriter _traceFileWriter = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), 4096, leaveOpen: false);

                        trace.AddListener(_traceFileWriter);
                    }
                    catch (Exception ex)
                    {
                        streams.Error.WriteLine($"warning: unable to trace to file '{traceValue}': {ex.Message}");
                    }
                }
                else
                {
                    streams.Error.WriteLine($"warning: unknown value for trace '{traceValue}'");
                }
            }
        }
コード例 #2
0
 public LaunchApp(LaunchApp rhs)
 {
     Executable       = rhs.Executable;
     Arguments        = rhs.Arguments;
     WorkingDirectory = rhs.WorkingDirectory;
     OutputFilepath   = rhs.OutputFilepath;
     ShowWindow       = rhs.ShowWindow;
     AppendOutputFile = rhs.AppendOutputFile;
     Streams          = rhs.Streams;
 }
コード例 #3
0
        // Your application's entry point. Here you can initialize your MVVM framework, DI
        // container, etc.
        private static void AppMain(Avalonia.Application app, string[] args)
        {
            var cla = new CommandLineApplication();

            cla.HelpOption();
            var optionPromptType = cla.Option("-p|--prompt <USERPASS,AUTHCODE>", "The prompt type",
                                              CommandOptionType.SingleValue);
            var optionHostUrl = cla.Option("-h|--host <HOST_URL>", "The URL of the target host, displayed to the user and used to determine host type",
                                           CommandOptionType.SingleValue);
            var optionProxyUrl = cla.Option("--proxy <PROXY_URL>", "The URL of the proxy",
                                            CommandOptionType.SingleValue);
            var optionVerifySsl = cla.Option("--verifyssl <TRUE_FALSE>", "Whether SSL shoudl be verified or not",
                                             CommandOptionType.SingleValue);
            var optionOAuthConsumerKey = cla.Option("--oauthkey <KEY>", "The OAuth Consumer Key to use during OAuth flows",
                                                    CommandOptionType.SingleValue);
            var optionOAuthConsumerSecret = cla.Option("--oauthsecret <SECRET>", "The OAuth Consumer Secret to use during OAuth flows",
                                                       CommandOptionType.SingleValue);
            var optionTrace = cla.Option("--trace <TRUE_FALSE_FILEPATH>", "False for no logging, True to log to console, Filepath to log to file",
                                         CommandOptionType.SingleValue);

            cla.OnExecute(() =>
            {
                var prompt = optionPromptType.HasValue()
                            ? optionPromptType.Value()
                            : "userpass";

                var hostUrl = optionHostUrl.HasValue()
                            ? optionHostUrl.Value()
                            : BitbucketConstants.BitbucketBaseUrl; // default to https://bitbucket.org
                var proxyUrl = optionProxyUrl.HasValue()
                            ? optionProxyUrl.Value()
                            : null; // default to no proxy
                var verifySsl = optionVerifySsl.HasValue()
                            ? optionVerifySsl.Value()
                            : "true"; // default to true
                var oAuthConsumerKey = optionOAuthConsumerKey.HasValue()
                            ? optionOAuthConsumerKey.Value()
                            : null; // default to no key
                var oAuthConsumerSecret = optionOAuthConsumerSecret.HasValue()
                            ? optionOAuthConsumerSecret.Value()
                            : null; // default to no secret
                var traceConfig = optionTrace.HasValue()
                            ? optionTrace.Value()
                            : null; // default to no logging

                var streams = new StandardStreams();

                using (var trace = new Itofinity.Bitbucket.Authentication.Helpers.Microsoft.Git.CredentialManager.Trace())
                    using (var settings = new Settings(hostUrl, proxyUrl, verifySsl, oAuthConsumerKey, oAuthConsumerSecret, traceConfig))
                    {
                        var httpClientFactory = new HttpClientFactory(trace, settings, streams);

                        // Enable tracing
                        ConfigureTrace(trace, settings, streams);

                        var viewModel = GetViewModel(prompt, hostUrl, trace, httpClientFactory, settings);
                        var window    = GetWindow(viewModel);
                        app.Run(window);

                        if (viewModel.Output != null &&
                            viewModel.Output.Any())
                        {
                            streams.Out.WriteDictionary(viewModel.Output);
                        }
                    }

                return(0);
            });

            var result = cla.Execute(args);
        }