Skip to content

Commit

Permalink
Add an option to turn off source control in func init. Fixes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmelsayed committed May 24, 2017
1 parent b2e05d2 commit 5b4bfc0
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -60,10 +61,17 @@ class InitAction : BaseAction

public override ICommandLineParserResult ParseArgs(string[] args)
{
if (args.Any())
Parser
.Setup<bool>('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);
}

Expand Down Expand Up @@ -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"));
}
}
}
}

0 comments on commit 5b4bfc0

Please sign in to comment.