Browse Source

Fix check for tye.yaml (#68)

pull/71/head
Justin Kotalik 7 years ago
committed by GitHub
parent
commit
990197b56e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/tye/Program.InitCommand.cs

26
src/tye/Program.InitCommand.cs

@ -18,17 +18,20 @@ namespace Tye
CommonArguments.Path_Optional,
};
command.Handler = CommandHandler.Create<IConsole, FileInfo?>((console, path) =>
command.AddOption(new Option("--force")
{
Description = "Overrides the tye.yaml file if already present for project.",
Required = false
});
command.Handler = CommandHandler.Create<IConsole, FileInfo?, bool>((console, path, force) =>
{
var output = new OutputContext(console, Verbosity.Info);
output.WriteBanner();
if (path is FileInfo &&
path.Exists &&
(string.Equals(".yml", path.Extension, StringComparison.OrdinalIgnoreCase) ||
string.Equals(".yaml", path.Extension, StringComparison.OrdinalIgnoreCase)))
if (path is FileInfo && path.Exists && !force)
{
throw new CommandException($"File '{path.FullName}' already exists.");
ThrowIfTyeFilePresent(path, "tye.yml");
ThrowIfTyeFilePresent(path, "tye.yaml");
}
var template = @"
@ -105,5 +108,14 @@ services:
return command;
}
private static void ThrowIfTyeFilePresent(FileInfo? path, string yml)
{
var tyeYaml = Path.Combine(path!.DirectoryName, yml);
if (File.Exists(tyeYaml))
{
throw new CommandException($"File '{tyeYaml}' already exists. Use --force to override the {yml} file if desired.");
}
}
}
}

Loading…
Cancel
Save