Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit e6257f9

Browse files
committed
some fixes in pack command
1 parent 9e05986 commit e6257f9

6 files changed

+62
-40
lines changed

Commands/PackCommand.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System;
2-
using System.IO;
3-
using System.Linq;
41
using Common;
52
using Common.YamlParsers;
3+
using System.IO;
4+
using System.Linq;
65

76
namespace Commands
87
{
@@ -79,8 +78,9 @@ protected override void ParseArgs(string[] args)
7978
}
8079

8180
public override string HelpMessage => @"
82-
Pack project to nuget package. Replace file references to package references in csproj file and run 'dotnet pack' command.
83-
Allows to publish nuget package to use outside of cement.
81+
Packs project to nuget package. Replaces file references to package references in csproj file and runs 'dotnet pack' command.
82+
Allows to publish nuget package to use outside of cement.
83+
Searches cement deps in nuget by module name.
8484
8585
Usage:
8686
cm pack [-v|--verbose|-w|-W|--warnings] [-p|--progress] [-c configName] <project-file>

Commands/ReadmeGenerator.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace Commands
44
{
@@ -47,6 +47,8 @@ public static string Generate()
4747
{commands["show-deps"].HelpMessage}
4848
### cm usages
4949
{commands["usages"].HelpMessage}
50+
### cm pack
51+
{commands["pack"].HelpMessage}
5052
5153
### cm status
5254
{commands["status"].HelpMessage}";

Common/CompleteCommandAutomata.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
1+
using Common.YamlParsers;
2+
using log4net;
3+
using System;
24
using System.Collections.Generic;
35
using System.IO;
46
using System.Linq;
5-
using Common.YamlParsers;
6-
using log4net;
77

88
namespace Common
99
{
@@ -145,6 +145,9 @@ private TokensList RefAddComplete()
145145

146146
private TokensList MoudleCsprojs()
147147
{
148+
var workspace = Helper.GetWorkspaceDirectory(Directory.GetCurrentDirectory()) ?? Directory.GetCurrentDirectory();
149+
Helper.SetWorkspace(workspace);
150+
148151
var moduleDirectory = Helper.GetModuleDirectory(Directory.GetCurrentDirectory());
149152
if (moduleDirectory == null)
150153
return null;
@@ -214,6 +217,7 @@ private void InitAutomata()
214217
{"show", ModuleKeyWithModules}
215218
}
216219
},
220+
{"pack", MoudleCsprojs },
217221
"--version"
218222
};
219223

Common/NuGetHelper.cs

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
using System.IO;
21
using log4net;
2+
using System;
3+
using System.IO;
34

45
namespace Common
56
{
67
public static class NuGetHelper
78
{
89
private static readonly ILog Log = LogManager.GetLogger(typeof(NuGetHelper));
910

11+
public static string GetNugetPackageVersion(string packageName, string nugetRunCommand)
12+
{
13+
var shellRunner = new ShellRunner();
14+
ConsoleWriter.WriteProgressWithoutSave("Get package verion for " + packageName);
15+
16+
shellRunner.Run($"{nugetRunCommand} list {packageName} -NonInteractive");
17+
foreach (var line in shellRunner.Output.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
18+
{
19+
var lineTokens = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
20+
if (lineTokens.Length == 2 && lineTokens[0].Equals(packageName, StringComparison.InvariantCultureIgnoreCase))
21+
{
22+
var msg = $"Got package version: {lineTokens[1]} for {packageName}";
23+
Log.Info(msg);
24+
ConsoleWriter.WriteInfo(msg);
25+
return lineTokens[1];
26+
}
27+
}
28+
29+
var message = "not found package version. nuget output: " + shellRunner.Output + shellRunner.Errors;
30+
Log.Debug(message);
31+
ConsoleWriter.WriteWarning(message);
32+
return null;
33+
}
34+
1035
public static string GetNugetRunCommand()
1136
{
1237
var nuGetPath = GetNuGetPath();

Common/ProjectFile.cs

+3-30
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
using log4net;
12
using System;
23
using System.Collections.Generic;
3-
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6-
using System.Text;
76
using System.Xml;
8-
using log4net;
97

108
namespace Common
119
{
@@ -187,7 +185,7 @@ public XmlDocument CreateCsProjWithNugetReferences(List<Dep> deps, string module
187185
var includeAttr = patchedProjDoc.CreateAttribute("Include");
188186
includeAttr.Value = dep.Name;
189187
refElement.Attributes.Append(includeAttr);
190-
var packageVersion = GetNugetPackageVersion(moduleDirectory, dep.Name, nugetRunCommand);
188+
var packageVersion = NuGetHelper.GetNugetPackageVersion(dep.Name, nugetRunCommand);
191189
if (!string.IsNullOrEmpty(packageVersion))
192190
{
193191
var versionAttr = patchedProjDoc.CreateAttribute("Version");
@@ -199,32 +197,7 @@ public XmlDocument CreateCsProjWithNugetReferences(List<Dep> deps, string module
199197

200198
return patchedProjDoc;
201199
}
202-
203-
private string GetNugetPackageVersion(string directory, string packageName, string nugetRunCommand)
204-
{
205-
var shellRunner = new ShellRunner();
206-
ConsoleWriter.WriteInfo("Get package verion for " + packageName);
207-
208-
shellRunner.RunInDirectory(directory, $"{nugetRunCommand} list {packageName} -NonInteractive");
209-
foreach (var line in shellRunner.Output.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
210-
{
211-
var lineTokens = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
212-
if (lineTokens.Length == 2 &&
213-
lineTokens[0].Equals(packageName, StringComparison.InvariantCultureIgnoreCase))
214-
{
215-
var msg = $"Got package version: {lineTokens[1]} for {packageName}";
216-
log.Info(msg);
217-
ConsoleWriter.WriteInfo(msg);
218-
return lineTokens[1];
219-
}
220-
}
221-
222-
var message = "not found package version. nuget output: " + shellRunner.Output + shellRunner.Errors;
223-
log.Debug(message);
224-
ConsoleWriter.WriteInfo(message);
225-
return null;
226-
}
227-
200+
228201
public void Save()
229202
{
230203
XmlDocumentHelper.Save(Document, FilePath, lineEndings);

README-commands.md

+18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
[cm usages](#cm-usages)
3636

37+
[cm pack](#cm-pack)
38+
3739
[cm status](#cm-status)
3840

3941

@@ -315,6 +317,22 @@
315317
cm usages grep "new Class" "Class.New" -- *.cs
316318
show lines contains "new Class" or "Class.New" in modules linked to the current, only in *.cs files
317319

320+
### cm pack
321+
322+
Packs project to nuget package. Replaces file references to package references in csproj file and runs 'dotnet pack' command.
323+
Allows to publish nuget package to use outside of cement.
324+
Searches cement deps in nuget by module name.
325+
326+
Usage:
327+
cm pack [-v|--verbose|-w|-W|--warnings] [-p|--progress] [-c configName] <project-file>
328+
-c/--configuration - build package for specific configuration
329+
330+
-v/--verbose - show full msbuild output
331+
-w/--warnings - show warnings
332+
-W - show only obsolete warnings
333+
334+
-p/--progress - show msbuild output in one line
335+
318336

319337
### cm status
320338

0 commit comments

Comments
 (0)