示例#1
0
        public int ExecuteCommand(CliExecutionContext context)
        {
            if (_osService.IsRoot())
            {
                return((int)ExitCode.SuRunAlreadyElevated);
            }

            _sudoService.VerifyAdminRole("su", ExitCode.SuRunNoAdmin);

            var tool = _sudoService.GetTool(CommandLineToolName, out string toolName, ExitCode.SuRunUnknownTool);

            return((int)(tool switch
            {
                TerminalTool.PowerShell => _sudoService.Run(toolName, "-nologo", ExitCode.SuRunUserDeclined),
                TerminalTool.Cmd => _sudoService.Run(toolName, "/k", ExitCode.SuRunUserDeclined),
                _ => ExitCode.SuRunUnknownTool,
            }));
        protected override int OnExecuteCommand(CliExecutionContext context)
        {
            _sudoService.VerifyAdminRole("sudo", ExitCode.SudoRunNoAdmin);

            return((int)_sudoService.Run(CommandLineToolName, x => x switch
            {
                TerminalTool.Cmd => Command ?? _sudoService.GetLastCmdCommand(),
                _ => Command ?? "Write-Host 'Last command could not be determined!' -Foreground Red",
            }));
示例#3
0
        protected override int OnExecuteCommand(CliExecutionContext context)
        {
            _sudoService.VerifyAdminRole("sudo", ExitCode.SudoRunNoAdmin);

            var allArgs = Environment.GetCommandLineArgs();
            IEnumerable <string> args = allArgs.Skip(string.Equals(allArgs[2], "run", StringComparison.OrdinalIgnoreCase) ? 3 : 2);

            var ddIdx = args.IndexOf("--");
            var tIdx  = args.IndexOf(x => string.Equals(x, "--tool", StringComparison.OrdinalIgnoreCase));

            if (ddIdx >= 0)
            {
                args = args.Take(ddIdx).Concat(args.Skip(ddIdx + 1));
            }
            if (tIdx >= 0 && (ddIdx < 0 || tIdx < ddIdx))
            {
                args = args.Take(tIdx).Concat(args.Skip(tIdx + 2));
            }

            return((int)_sudoService.Run(CommandLineToolName, x => x switch
            {
                TerminalTool.PowerShell => string.Join(" ", args.Select(SerializePS)),
                _ => string.Join(" ", args.Select(SerializeCmd)),
            }));