From 5b4bfc0b368adc1710baf260590268c9e38213e5 Mon Sep 17 00:00:00 2001 From: Ahmed ElSayed Date: Tue, 23 May 2017 18:03:01 -0700 Subject: [PATCH] Add an option to turn off source control in func init. Fixes #104 --- .../Actions/LocalActions/InitAction.cs | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs b/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs index 2860e29ac..659ddd63d 100644 --- a/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs +++ b/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs @@ -18,6 +18,7 @@ namespace Azure.Functions.Cli.Actions.LocalActions class InitAction : BaseAction { public SourceControl SourceControl { get; set; } = SourceControl.Git; + public bool InitSourceControl { get; set; } public string FolderName { get; set; } = string.Empty; @@ -60,10 +61,17 @@ class InitAction : BaseAction public override ICommandLineParserResult ParseArgs(string[] args) { - if (args.Any()) + Parser + .Setup('n', "no-source-control") + .SetDefault(false) + .WithDescription("Skip running git init. Default is false.") + .Callback(f => InitSourceControl = !f); + + if (args.Any() && !args.First().StartsWith("-")) { FolderName = args.First(); } + return base.ParseArgs(args); } @@ -113,24 +121,27 @@ public override async Task RunAsync() ColoredConsole.Error.WriteLine(ErrorColor("Unable to configure launch.json. Check the file for more info")); } - try + if (InitSourceControl) { - var checkGitRepoExe = new Executable("git", "rev-parse --git-dir"); - var result = await checkGitRepoExe.RunAsync(); - if (result != 0) + try { - var exe = new Executable("git", $"init"); - await exe.RunAsync(l => ColoredConsole.WriteLine(l), l => ColoredConsole.Error.WriteLine(l)); + var checkGitRepoExe = new Executable("git", "rev-parse --git-dir"); + var result = await checkGitRepoExe.RunAsync(); + if (result != 0) + { + var exe = new Executable("git", $"init"); + await exe.RunAsync(l => ColoredConsole.WriteLine(l), l => ColoredConsole.Error.WriteLine(l)); + } + else + { + ColoredConsole.WriteLine("Directory already a git repository."); + } } - else + catch (FileNotFoundException) { - ColoredConsole.WriteLine("Directory already a git repository."); + ColoredConsole.WriteLine(WarningColor("unable to find git on the path")); } } - catch (FileNotFoundException) - { - ColoredConsole.WriteLine(WarningColor("unable to find git on the path")); - } } } }