Skip to content

Commit 3055b79

Browse files
committed
addressing comments for dotnet subcommand
1 parent d9a23fd commit 3055b79

File tree

4 files changed

+30
-61
lines changed

4 files changed

+30
-61
lines changed

src/Cli/func/Actions/LocalActions/PackAction/DotnetPackSubcommandAction.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Azure.Functions.Cli.Actions.LocalActions.PackAction
1212
{
13-
[Action(Name = "pack dotnet", ParentCommandName = "pack", ShowInHelp = false, HelpText = ".NET specific arguments")]
13+
[Action(Name = "pack dotnet", ParentCommandName = "pack", ShowInHelp = false, HelpText = "Arguments specific to .NET apps when running func pack")]
1414
internal class DotnetPackSubcommandAction : BaseAction
1515
{
1616
private readonly ISecretsManager _secretsManager;
@@ -31,17 +31,25 @@ public async Task RunAsync(PackOptions packOptions)
3131
var functionAppRoot = PackHelpers.ResolveFunctionAppRoot(packOptions.FolderPath);
3232
string packingRoot = functionAppRoot;
3333

34+
if (!Directory.Exists(functionAppRoot))
35+
{
36+
throw new CliException($"Directory not found to pack: {functionAppRoot}");
37+
}
38+
3439
if (packOptions.NoBuild)
3540
{
3641
// For --no-build, treat FolderPath as the build output directory
3742
if (string.IsNullOrEmpty(packOptions.FolderPath))
3843
{
39-
throw new CliException("When using --no-build for .NET projects, you must specify the path to the build output directory (e.g., ./bin/Release/net8.0/publish)");
44+
ColoredConsole.WriteLine(WarningColor("No folder path specified. Using current directory as build output directory."));
45+
packingRoot = Environment.CurrentDirectory;
46+
}
47+
else
48+
{
49+
packingRoot = Path.IsPathRooted(packOptions.FolderPath)
50+
? packOptions.FolderPath
51+
: Path.Combine(Environment.CurrentDirectory, packOptions.FolderPath);
4052
}
41-
42-
packingRoot = Path.IsPathRooted(packOptions.FolderPath)
43-
? packOptions.FolderPath
44-
: Path.Combine(Environment.CurrentDirectory, packOptions.FolderPath);
4553

4654
if (!Directory.Exists(packingRoot))
4755
{
@@ -78,7 +86,7 @@ public async Task RunAsync(PackOptions packOptions)
7886
public override Task RunAsync()
7987
{
8088
// Keep this in case the customer tries to run func pack dotnet, since this subcommand is not meant to be run directly.
81-
throw new InvalidOperationException("Invalid command. Please run func pack instead with valid arguments. To see a list of valid arguments, please see func --help.");
89+
return Task.CompletedTask;
8290
}
8391

8492
private void ValidateDotNetPublishDirectory(string path)
@@ -88,7 +96,7 @@ private void ValidateDotNetPublishDirectory(string path)
8896
{
8997
if (!FileSystemHelpers.FileExists(Path.Combine(path, file)))
9098
{
91-
throw new CliException($"Required file {file} not found in build output directory: {path}");
99+
throw new CliException($"Required file '{file}' not found in build output directory: {path}");
92100
}
93101
}
94102
}
@@ -106,7 +114,7 @@ private async Task RunDotNetPublish(string functionAppRoot)
106114
}
107115

108116
// Run dotnet publish
109-
var exe = new Executable("dotnet", $"publish --configuration Release --output \"{outputPath}\"", workingDirectory: functionAppRoot);
117+
var exe = new Executable("dotnet", $"publish --output \"{outputPath}\"", workingDirectory: functionAppRoot);
110118
var exitCode = await exe.RunAsync(
111119
o => ColoredConsole.WriteLine(o),
112120
e => ColoredConsole.Error.WriteLine(ErrorColor(e)));

src/Cli/func/Actions/LocalActions/PackAction/PackAction.cs

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Azure.Functions.Cli.Actions.LocalActions.PackAction
1212
{
13-
[Action(Name = "pack", HelpText = "Pack function app into a zip that's ready to run.", ShowInHelp = true)]
13+
[Action(Name = "pack", HelpText = "Pack function app into a zip that's ready to deploy.", ShowInHelp = true)]
1414
internal class PackAction : BaseAction
1515
{
1616
private readonly ISecretsManager _secretsManager;
@@ -32,17 +32,18 @@ public override ICommandLineParserResult ParseArgs(string[] args)
3232
{
3333
Parser
3434
.Setup<string>('o', "output")
35-
.WithDescription("output path for the packed archive")
35+
.WithDescription("Specifies the file path where the packed ZIP archive will be created.")
3636
.Callback(o => OutputPath = o);
3737

3838
Parser
3939
.Setup<bool>("no-build")
40-
.WithDescription("Skip running build for specific language if it is required")
40+
.WithDescription("Do not build the project before packaging. Optionally provide a directory when func pack as the first argument that has the build contents." +
41+
"Otherwise, default is the current directory.")
4142
.Callback(n => NoBuild = n);
4243

4344
Parser
4445
.Setup<string>("preserve-executables")
45-
.WithDescription("Comma separated list of executables to indicate which bits are to be set as executable in the zip file.")
46+
.WithDescription("Comma - separated list of executable files to specify which files should be set as executable in the zip archive.")
4647
.Callback(p => PreserveExecutables = p.Split(',').Select(s => s.Trim()).ToArray());
4748

4849
if (args.Any() && !args.First().StartsWith("-"))
@@ -68,54 +69,14 @@ public override async Task RunAsync()
6869
};
6970

7071
// Internally dispatch to runtime-specific subcommand
71-
await RunRuntimeSpecificPack(workerRuntime, packOptions);
72+
await RunRuntimeSpecificPackAsync(workerRuntime, packOptions);
7273
}
7374

74-
private async Task RunRuntimeSpecificPack(WorkerRuntime runtime, PackOptions packOptions)
75-
{
76-
// Internally dispatch to the appropriate subcommand handler
77-
switch (runtime)
75+
private async Task RunRuntimeSpecificPackAsync(WorkerRuntime runtime, PackOptions packOptions) =>
76+
await (runtime switch
7877
{
79-
case WorkerRuntime.Dotnet:
80-
case WorkerRuntime.DotnetIsolated:
81-
var dotnetSubCommand = new DotnetPackSubcommandAction(_secretsManager);
82-
await dotnetSubCommand.RunAsync(packOptions);
83-
break;
84-
/*
85-
case WorkerRuntime.Python:
86-
var pythonSubCommand = new PythonPackSubCommand(_secretsManager, this);
87-
await pythonSubCommand.ParseAndRunAsync(args);
88-
break;
89-
case WorkerRuntime.Node:
90-
var nodeSubCommand = new NodePackSubCommand(_secretsManager, this);
91-
await nodeSubCommand.ParseAndRunAsync(args);
92-
break;
93-
case WorkerRuntime.Java:
94-
var javaSubCommand = new JavaPackSubCommand(_secretsManager, this);
95-
await javaSubCommand.ParseAndRunAsync(args);
96-
break;
97-
case WorkerRuntime.Powershell:
98-
var powershellSubCommand = new PowerShellPackSubCommand(_secretsManager, this);
99-
await powershellSubCommand.ParseAndRunAsync(args);
100-
break;
101-
*/
102-
default:
103-
// Keep the default behavior for now until we have created subcommands for other runtimes
104-
var functionAppRoot = PackHelpers.ResolveFunctionAppRoot(FolderPath);
105-
PackHelpers.ValidateFunctionAppRoot(functionAppRoot);
106-
107-
var outputPath = PackHelpers.ResolveOutputPath(functionAppRoot, OutputPath);
108-
PackHelpers.CleanupExistingPackage(outputPath);
109-
110-
if (!NoBuild)
111-
{
112-
var installExtensionAction = new InstallExtensionAction(_secretsManager, false);
113-
await installExtensionAction.RunAsync();
114-
}
115-
116-
await PackHelpers.CreatePackage(functionAppRoot, outputPath, NoBuild, TelemetryCommandEvents);
117-
break;
118-
}
119-
}
78+
WorkerRuntime.Dotnet or WorkerRuntime.DotnetIsolated => new DotnetPackSubcommandAction(_secretsManager).RunAsync(packOptions),
79+
_ => throw new CliException($"Unsupported runtime: {runtime}")
80+
});
12081
}
12182
}

src/Cli/func/Actions/LocalActions/PackAction/PackHelpers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Azure.Functions.Cli.Helpers;
66
using Colors.Net;
77
using Microsoft.Azure.WebJobs.Script;
8+
using static Azure.Functions.Cli.Common.OutputTheme;
89

910
namespace Azure.Functions.Cli.Actions.LocalActions.PackAction
1011
{
@@ -56,7 +57,7 @@ public static void CleanupExistingPackage(string outputPath)
5657
}
5758
catch (Exception)
5859
{
59-
throw new CliException($"Could not delete {outputPath}");
60+
ColoredConsole.WriteLine(WarningColor($"Could not delete {outputPath}"));
6061
}
6162
}
6263
}

src/Cli/func/Actions/LocalActions/PackAction/PackOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
54
namespace Azure.Functions.Cli.Actions.LocalActions.PackAction
65
{
76
public class PackOptions

0 commit comments

Comments
 (0)