Skip to content

Commit

Permalink
Update Command line switches
Browse files Browse the repository at this point in the history
Based on feedback from @KathleenDollard and Bri Achtman
  • Loading branch information
swaroop-sridhar committed Mar 13, 2019
1 parent ef96034 commit 8e2e112
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
20 changes: 10 additions & 10 deletions src/managed/Microsoft.DotNet.Build.Bundle/Bundler.cs
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Build.Bundle
public class Bundler
{
string HostName;
string ContentDir;
string SourceDir;
string OutputDir;
bool EmbedPDBs;

Expand All @@ -33,9 +33,9 @@ public class Bundler

public static string Version => (Manifest.MajorVersion + "." + Manifest.MinorVersion);

public Bundler(string hostName, string contentDir, string outputDir, bool embedPDBs)
public Bundler(string hostName, string sourceDir, string outputDir, bool embedPDBs)
{
ContentDir = contentDir;
SourceDir = sourceDir;
OutputDir = outputDir;
HostName = hostName;
EmbedPDBs = embedPDBs;
Expand All @@ -44,9 +44,9 @@ public Bundler(string hostName, string contentDir, string outputDir, bool embedP
void ValidateFiles()
{
// Check required directories
if (!Directory.Exists(ContentDir))
if (!Directory.Exists(SourceDir))
{
throw new BundleException("Dirctory not found: " + ContentDir);
throw new BundleException("Dirctory not found: " + SourceDir);
}
if (!Directory.Exists(OutputDir))
{
Expand All @@ -63,7 +63,7 @@ void ValidateFiles()
// Check that required files exist on disk.
Action<string> checkFileExists = (string name) =>
{
string path = Path.Combine(ContentDir, name);
string path = Path.Combine(SourceDir, name);
if (!File.Exists(path))
{
throw new BundleException("File not found: " + path);
Expand Down Expand Up @@ -167,7 +167,7 @@ void GenerateBundle()

// Start with a copy of the host executable.
// Copy the file to preserve its permissions.
File.Copy(Path.Combine(ContentDir, HostName), bundlePath, overwrite: true);
File.Copy(Path.Combine(SourceDir, HostName), bundlePath, overwrite: true);

using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(bundlePath)))
{
Expand All @@ -177,9 +177,9 @@ void GenerateBundle()
bundle.Position = bundle.Length;

// Sort the file names to keep the bundle construction deterministic.
string[] contents = Directory.GetFiles(ContentDir);
Array.Sort(contents, StringComparer.Ordinal);
foreach (string filePath in contents)
string[] sources = Directory.GetFiles(SourceDir);
Array.Sort(sources, StringComparer.Ordinal);
foreach (string filePath in sources)
{
string fileName = Path.GetFileName(filePath);

Expand Down
53 changes: 33 additions & 20 deletions src/managed/Microsoft.DotNet.Build.Bundle/Program.cs
Expand Up @@ -26,7 +26,7 @@ enum RunMode
// Bundle options:
static bool EmbedPDBs = false;
static string HostName;
static string ContentDir;
static string SourceDir;

// Extract options:
static string BundleToExtract;
Expand All @@ -35,16 +35,23 @@ static void Usage()
{
Console.WriteLine($".NET Core Bundler (version {Bundler.Version})");
Console.WriteLine("Usage: bundle <options>");
Console.WriteLine(" -d <path> Directory containing the files to bundle (required for bundling)");
Console.WriteLine(" -a <name> Application host within the content directory (required for bundling)");
Console.WriteLine(" --pdb Embed PDB files");
Console.WriteLine(" -e <path> Extract files from the specified bundle");
Console.WriteLine(" -o <path> Output directory (default: current)");
Console.WriteLine(" -v Generate verbose output");
Console.WriteLine(" -? Display usage information");
Console.WriteLine("");

This comment has been minimized.

Copy link
@KathleenDollard

KathleenDollard Mar 13, 2019

I like the approach you took here. It's not consistent with the CLI, but it will help customers understand which options make sense together.

Console.WriteLine("Bundle options:");
Console.WriteLine(" --source <PATH> Directory containing files to bundle (required).");
Console.WriteLine(" --apphost <NAME> Application host within source directory (required).");
Console.WriteLine(" --pdb Embed PDB files.");
Console.WriteLine("");
Console.WriteLine("Extract options:");
Console.WriteLine(" --extract <PATH> Extract files from the specified bundle.");
Console.WriteLine("");
Console.WriteLine("Common options:");
Console.WriteLine(" -o|--output <PATH> Output directory (default: current).");
Console.WriteLine(" -d|--diagnostics Enable diagnostic output.");
Console.WriteLine(" -?|-h|--help Display usage information.");
Console.WriteLine("");
Console.WriteLine("Examples:");
Console.WriteLine("Bundle: bundle -d <publish-dir> -a <host-exe> -o <output-dir>");
Console.WriteLine("Extract: bundle -e <bundle-exe> -o <output-dir>");
Console.WriteLine("Bundle: bundle --source <publish-dir> --apphost <host-exe> -o <output-dir>");
Console.WriteLine("Extract: bundle --extract <bundle-exe> -o <output-dir>");
}

public static void Log(string fmt, params object[] args)
Expand Down Expand Up @@ -79,46 +86,52 @@ static void ParseArgs(string[] args)
{
case "-?":
case "-h":
case "--help":
Mode = RunMode.Help;
break;

case "-e":
case "--extract":
Mode = RunMode.Extract;
BundleToExtract = NextArg(arg);
break;

case "-v":
case "-d":
case "--diagnostics":
Verbose = true;
break;

case "-a":
case "--apphost":
HostName = NextArg(arg);
break;

case "-d":
ContentDir = NextArg(arg);
case "--source":
SourceDir = NextArg(arg);
break;

case "-o":
case "--output":
OutputDir = NextArg(arg);
break;

case "--pdb":
EmbedPDBs = true;
break;

default:
throw new BundleException("Invalid option: " + arg);
}
}

if (Mode == RunMode.Bundle)
{
if (ContentDir == null)
if (SourceDir == null)
{
throw new BundleException("Missing argument: -d");
throw new BundleException("Missing argument: source directory");
}

if (HostName == null)
{
throw new BundleException("Missing argument: -a");
throw new BundleException("Missing argument: host");
}
}

Expand All @@ -137,9 +150,9 @@ static void Run()
break;

case RunMode.Bundle:
Log($"Bundle from dir: {ContentDir}");
Log($"Bundle from dir: {SourceDir}");
Log($"Output Directory: {OutputDir}");
Bundler bundle = new Bundler(HostName, ContentDir, OutputDir, EmbedPDBs);
Bundler bundle = new Bundler(HostName, SourceDir, OutputDir, EmbedPDBs);
bundle.MakeBundle();
break;

Expand Down
10 changes: 5 additions & 5 deletions src/test/Microsoft.DotNet.Build.Bundle.Tests/BundleAndExtract.cs
Expand Up @@ -45,9 +45,9 @@ public void Test()
"Microsoft.DotNet.Build.Bundle",
"netcoreapp2.0",
"Microsoft.DotNet.Build.Bundle.dll");
string[] bundleArgs = { "-d", fixture.TestProject.OutputDirectory,
"-a", hostName,
"-o", singleFileDir };
string[] bundleArgs = { "--source", fixture.TestProject.OutputDirectory,
"--apphost", hostName,
"--output", singleFileDir };

dotnet.Exec(bundleDll, bundleArgs)
.CaptureStdErr()
Expand All @@ -58,8 +58,8 @@ public void Test()

// Extract the contents
string singleFile = Path.Combine(singleFileDir, hostName);
string[] extractArgs = { "-e", singleFile,
"-o", singleFileDir };
string[] extractArgs = { "--extract", singleFile,
"--output", singleFileDir };

dotnet.Exec(bundleDll, extractArgs)
.CaptureStdErr()
Expand Down

0 comments on commit 8e2e112

Please sign in to comment.