< Summary

Class:Mklinker.Commands.RemoveVariableCommand
Assembly:Mklinker
File(s):/home/travis/build/rubenchristoffer/Mklinker/Mklinker/Commands/RemoveVariableCommand.cs
Covered lines:15
Uncovered lines:4
Coverable lines:19
Total lines:44
Line coverage:78.9% (15 of 19)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor()100%100%
.ctor(...)10100%100%
Execute(...)4078.57%75%

File(s)

/home/travis/build/rubenchristoffer/Mklinker/Mklinker/Commands/RemoveVariableCommand.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO.Abstractions;
 4using System.Text;
 5using System.Linq;
 6using CommandLine;
 7using Mklinker.Abstractions;
 8
 9namespace Mklinker.Commands {
 10
 11  [Verb("removevar", HelpText = "Removes a variable from config file")]
 12  class RemoveVariableCommand : GlobalOptions, IDefaultCommandHandler {
 13
 14    [Value(0, HelpText = "The name of the variable", Required = true)]
 515    public string name { get; private set; }
 16
 017    public RemoveVariableCommand() : base() {}
 18
 419    public RemoveVariableCommand(string name, string path) : base(path) {
 220      this.name = name;
 221    }
 22
 223    public void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem) {
 024      if (!configHandler.DoesConfigExist(path)) {
 025        console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config
 026        return;
 27      }
 28
 229      IConfig config = configHandler.LoadConfig(path);
 330      Variable existingVariable = config.Variables.FirstOrDefault(variable => variable.name.Equals(name, StringCompariso
 31
 332      if (existingVariable == null) {
 133        console.WriteLine($"A variable with name '{ name }' does not exist", IConsole.ContentType.Negative);
 234      } else {
 135        config.Variables.Remove(existingVariable);
 136        configHandler.SaveConfig(config, path);
 37
 138        console.WriteLine($"Variable with name '{ name }' has been removed");
 139      }
 240    }
 41
 42  }
 43
 44}