示例#1
0
        static void Main(string[] args)
        {
            Console.CancelKeyPress += (s, e) =>
            {
                _quit    = true;
                e.Cancel = true;
                MeadowDeviceManager.CurrentDevice?.SerialPort?.Close();
            };

            CompletionBehavior behavior = CompletionBehavior.Success;

            if (args.Length == 0)
            {
                args = new string[] { "--help" };
            }
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(options =>
            {
                if (options.ListPorts)
                {
                    Console.WriteLine("Available serial ports\n----------------------");

                    var ports = MeadowSerialDevice.GetAvailableSerialPorts();
                    if (ports == null || ports.Length == 0)
                    {
                        Console.WriteLine("\t <no ports found>");
                    }
                    else
                    {
                        foreach (var p in ports)
                        {
                            Console.WriteLine($"\t{p}");
                        }
                    }
                    Console.WriteLine($"\n");
                }
                else
                {
                    if (options.Dfu)
                    {
                        //ToDo update to use command line args for os and user
                        DfuUpload.FlashNuttx(options.DfuOsPath, options.DfuUserPath);
                    }
                    else
                    {
                        SyncArgsCache(options);
                        try
                        {
                            behavior = ProcessHcom(options).Result;
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            });

            if (System.Diagnostics.Debugger.IsAttached)
            {
                behavior = CompletionBehavior.KeepConsoleOpen;
            }

            if ((behavior & CompletionBehavior.KeepConsoleOpen) == CompletionBehavior.KeepConsoleOpen)
            {
                Console.Read();
            }
            else
            {
                Thread.Sleep(500);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
            };

            CompletionBehavior behavior = CompletionBehavior.Success;

            DownloadManager downloadManager = new DownloadManager();
            var             check           = downloadManager.CheckForUpdates().Result;

            if (check.updateExists)
            {
                Console.WriteLine($"CLI version {check.latestVersion} is available. To update, run: {DownloadManager.UpdateCommand}");
            }

            if (args.Length == 0)
            {
                args = new string[] { "--help" };
            }

            var parser = new Parser(settings => {
                settings.CaseSensitive          = false;
                settings.AutoVersion            = false; // needed to supercede the built in --version command
                settings.HelpWriter             = Console.Out;
                settings.IgnoreUnknownArguments = true;
            });

            parser.ParseArguments <Options>(args)
            .WithParsed <Options>(options =>
            {
                if (options.ListPorts)
                {
                    Console.WriteLine("Available serial ports\n----------------------");

                    var ports = MeadowSerialDevice.GetAvailableSerialPorts();
                    if (ports == null || ports.Length == 0)
                    {
                        Console.WriteLine("\t <no ports found>");
                    }
                    else
                    {
                        foreach (var p in ports)
                        {
                            Console.WriteLine($"\t{p}");
                        }
                    }
                    Console.WriteLine($"\n");
                }
                else
                {
                    if (options.DownloadLatest)
                    {
                        downloadManager.DownloadLatest().Wait();
                    }
                    else if (options.FlashOS)
                    {
                        DfuUpload.FlashOS(options.FileName);
                    }
                    else if (options.Login)
                    {
                        IdentityManager identityManager = new IdentityManager();
                        var result = identityManager.LoginAsync().Result;
                        if (result)
                        {
                            var cred = identityManager.GetCredentials(identityManager.WLRefreshCredentialName);
                            Console.WriteLine($"Signed in as {cred.username}");
                        }
                    }
                    else if (options.Logout)
                    {
                        IdentityManager identityManager = new IdentityManager();
                        identityManager.Logout();
                    }
                    else if (options.InstallDfuUtil)
                    {
                        if (Environment.OSVersion.Platform != PlatformID.Win32NT)
                        {
                            Console.WriteLine("To install on macOS, run: brew install dfu-util");
                        }
                        else
                        {
                            downloadManager.InstallDfuUtil(Environment.Is64BitOperatingSystem);
                        }
                    }
                    else if (args[0].Equals("--version", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine($"Current version: {check.currentVersion}");
                    }
                    else
                    {
                        SyncArgsCache(options);
                        try
                        {
                            ProcessHcom(options).Wait();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"An unexpected error occurred: {ex?.InnerException?.Message}");
                        }
                    }
                }
            });

            //if (System.Diagnostics.Debugger.IsAttached)
            //{
            //    behavior = CompletionBehavior.KeepConsoleOpen;
            //}

            Environment.Exit(0);
        }