示例#1
0
        public async Task EchoTest()
        {
            var shell = new ShellCmd();

            Assert.Equal("hi", (await shell.GetOutputAsync("echo hi")).Trim());

            var expected = "^\"'";
            var command  = "echo" + CmdHelpers.GetEchoArguments(expected);

            Assert.Equal(expected, (await shell.GetOutputAsync(command)).Trim());
        }
        /// <inheritdoc />
        protected override void Do(CommandLineApplication app, IConsole console)
        {
            // getting stack info
            var stack = ApiClient.GetStacks().FirstOrDefault(s => s.Name == StackName);

            if (stack == null)
            {
                throw new Exception("Stack with this name is not found");
            }

            var stackId = int.Parse(stack.Id);
            // check file
            string fileContent = null;

            if (!string.IsNullOrWhiteSpace(FilePath))
            {
                if (!File.Exists(FilePath))
                {
                    throw new Exception("Definition file is not found. Provide valid path.");
                }

                fileContent = File.ReadAllText(FilePath);
            }

            if (FileFromStdin && fileContent == null)
            {
                var    sb = new StringBuilder();
                string s;
                while ((s = Console.ReadLine()) != null)
                {
                    sb.AppendLine(s);
                }

                fileContent = sb.ToString();
            }

            var envs = CmdHelpers.ParseEnvs(Envs);

            // if file content not provided (we use old file and change only provided env vars)
            if (fileContent == null)
            {
                envs.AddRange(stack.Env.Where(e => envs.All(newEnv => newEnv.Name != e.Name)));
                fileContent = ApiClient.GetStackFile(stackId);
            }

            console.Write("Sending stack update request to Portainer...");
            ApiClient.UpdateStack(stackId, envs, fileContent, prune: false, stack.EndpointId);
            console.WriteLine("Done!");
        }
示例#3
0
        /// <inheritdoc />
        protected override void Do(CommandLineApplication app, IConsole console)
        {
            if (!File.Exists(FilePath))
            {
                throw new Exception("Stack definition file is not found. Please, give correct path to file.");
            }

            var stackEnvs = CmdHelpers.ParseEnvs(Envs);

            // 1 - swarm stack
            console.WriteLine("Sending deploy request to Portainer...");
            var result = ApiClient.DeployStack(endpointId: EndpointId,
                                               StackName,
                                               SwarmId,
                                               FilePath,
                                               stackEnvs);

            console.WriteLine("Stack deployed.");
        }
示例#4
0
 /// <inheritdoc />
 public int OnExecute(CommandLineApplication app, IConsole console) =>
 CmdHelpers.SpecifyCommandResult(app, console);