< Summary

Class:Mklinker.Commands.LinkAllCommand
Assembly:Mklinker
File(s):/home/travis/build/rubenchristoffer/Mklinker/Mklinker/Commands/LinkAllCommand.cs
Covered lines:21
Uncovered lines:12
Coverable lines:33
Total lines:67
Line coverage:63.6% (21 of 33)
Covered branches:11
Total branches:16
Branch coverage:68.7% (11 of 16)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor()100%100%
.ctor(...)10100%100%
Execute(...)12058.33%58.33%
CreateSubDirectories(...)40100%100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.IO.Abstractions;
 3using System.Diagnostics;
 4using CommandLine;
 5using Mklinker.Abstractions;
 6using System.Text;
 7
 8namespace Mklinker.Commands {
 9
 10  [Verb ("linkall", HelpText = "Generates all links from config")]
 11  class LinkAllCommand : GlobalOptions {
 12
 13    [Option('v', "verbose", Default = false, HelpText = "Gives more detailed output", Required = false)]
 014    public bool verbose { get; private set; }
 15
 016    public LinkAllCommand() : base () {}
 617    public LinkAllCommand (string path) : base (path) {}
 18
 219    internal void Execute (IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, ILinker linker, IPath
 020      if (!configHandler.DoesConfigExist (path)) {
 021        console.WriteLine ($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a confi
 022        return;
 23      }
 24
 225      IConfig config = configHandler.LoadConfig (path);
 26
 227      console.WriteLine ("\nCreating links based on config...");
 28
 229      int successes = 0;
 30
 31      // Allow linkers verbose output if flag is set for this command
 232      linker.verbose = verbose;
 33
 1834      foreach (ConfigLink configLink in config.LinkList) {
 435        string resolvedSourcePath = pathResolver.GetAbsoluteResolvedPath (configLink.sourcePath, config.Variables);
 436        string resolvedTargetPath = pathResolver.GetAbsoluteResolvedPath (configLink.targetPath, config.Variables);
 37
 438        CreateSubDirectories (console, fileSystem, pathResolver, config, resolvedTargetPath);
 39
 040        if (fileSystem.Directory.Exists(resolvedTargetPath) || fileSystem.File.Exists(resolvedTargetPath)) {
 041          console.Write ($"Path '{configLink.targetPath}' already exists", IConsole.ContentType.Negative);
 42
 043          if (verbose) {
 044            console.Write ($" (resolved to '{resolvedTargetPath}')", IConsole.ContentType.Negative);
 045          }
 46
 047          console.WriteLine ();
 048        } else if (linker.CreateLink (resolvedSourcePath, resolvedTargetPath, configLink.linkType)) {
 449          successes++;
 450        }
 451      }
 52
 253      console.WriteLine ("\n### Finished! Created {0} / {1} links ###", successes, config.LinkList.Count);
 254    }
 55
 456    internal void CreateSubDirectories (IConsole console, IFileSystem fileSystem, IPathResolver pathResolver, IConfig co
 57      // Create sub-dirs if they do not exist
 458      string path = fileSystem.Path.GetDirectoryName (resolvedTargetPath);
 59
 660      if (path.Trim().Length != 0 && !fileSystem.Directory.Exists(path)) {
 261        fileSystem.Directory.CreateDirectory (path);
 262      }
 463    }
 64
 65  }
 66
 67}