Skip to content

Commit a97277f

Browse files
committed
Fixed unprinted version when default usage of cli.
1 parent 39990b4 commit a97277f

8 files changed

+61
-53
lines changed

RelaxVersioner.Core/Logger.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#nullable enable
1111

1212
using System;
13+
using System.ComponentModel;
1314
using System.IO;
1415

1516
namespace RelaxVersioner;
@@ -18,7 +19,9 @@ public enum LogImportance
1819
{
1920
Low = 1,
2021
Normal = 2,
21-
High =3
22+
High = 3,
23+
[EditorBrowsable(EditorBrowsableState.Never)]
24+
Ignore = 100,
2225
}
2326

2427
public abstract class Logger
@@ -28,6 +31,8 @@ public abstract class Logger
2831
protected Logger(string header) =>
2932
this.Header = header;
3033

34+
public abstract void SetImportance(LogImportance lowerImportance);
35+
3136
public abstract void Message(LogImportance importance, string message);
3237

3338
public virtual void Message(LogImportance importance, string format, params object?[] args) =>
@@ -55,11 +60,12 @@ public static Logger Create(string header, LogImportance lowerImportance, TextWr
5560

5661
internal sealed class TextWriterLogger : Logger
5762
{
58-
private readonly LogImportance lowerImportance;
5963
private readonly TextWriter @out;
6064
private readonly TextWriter warning;
6165
private readonly TextWriter error;
6266

67+
private LogImportance lowerImportance;
68+
6369
public TextWriterLogger(string header, LogImportance lowerImportance, TextWriter @out, TextWriter warning, TextWriter error) :
6470
base(header)
6571
{
@@ -69,9 +75,12 @@ public TextWriterLogger(string header, LogImportance lowerImportance, TextWriter
6975
this.error = error;
7076
}
7177

78+
public override void SetImportance(LogImportance lowerImportance) =>
79+
this.lowerImportance = lowerImportance;
80+
7281
public override void Message(LogImportance importance, string message)
7382
{
74-
if (importance >= lowerImportance)
83+
if (importance >= this.lowerImportance)
7584
{
7685
@out.WriteLine(message);
7786
}

RelaxVersioner.Core/Processor.cs

+2-19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public sealed class ProcessorContext
4141
public string BracketStart;
4242
public string BracketEnd;
4343
public bool IsDryRun;
44+
public bool IsQuietOnStandardOutput;
4445
public string[] NpmPrefixes;
4546
}
4647

@@ -60,21 +61,6 @@ public Processor(Logger logger)
6061

6162
public string[] Languages { get; }
6263

63-
private readonly struct TargetCommit
64-
{
65-
public readonly int StartDepth;
66-
public readonly Commit Commit;
67-
68-
public TargetCommit(int startDepth, Commit commit)
69-
{
70-
this.StartDepth = startDepth;
71-
this.Commit = commit;
72-
}
73-
74-
public override string ToString() =>
75-
$"StartDepth={this.StartDepth}, {this.Commit}";
76-
}
77-
7864
private static async Task<Result> WriteVersionSourceFileAsync(
7965
Logger logger,
8066
WriteProviderBase writeProvider,
@@ -155,10 +141,7 @@ static string FormatSignature(Signature? sig) => sig is { } s ?
155141
keyValues[entry.key] = entry.value;
156142
}
157143

158-
if (!string.IsNullOrWhiteSpace(context.OutputPath))
159-
{
160-
writeProvider.Write(context, keyValues, generated);
161-
}
144+
writeProvider.Write(context, keyValues, generated);
162145

163146
return new Result(
164147
versionLabel,

RelaxVersioner.Core/Writers/NpmReplaceProvider.cs

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ void ReplaceSubKey(string key)
102102
}
103103
else
104104
{
105+
if (context.IsQuietOnStandardOutput)
106+
{
107+
return;
108+
}
109+
105110
using var tr = context.ReplaceInputPath is { } rip ?
106111
new StreamReader(rip, Encoding.UTF8, true) :
107112
Console.In;

RelaxVersioner.Core/Writers/SourceCodeWriteProviderBase.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,12 @@ public override sealed void Write(
129129
var importSet = Utilities.AggregateImports(elementSet);
130130
var ruleSet = Utilities.AggregateRules(elementSet);
131131

132-
if (context.IsDryRun)
132+
if (context.IsDryRun ||
133+
string.IsNullOrWhiteSpace(context.OutputPath))
133134
{
134135
return;
135136
}
136137

137-
if (string.IsNullOrWhiteSpace(context.OutputPath))
138-
{
139-
throw new ArgumentException("Output path required.");
140-
}
141-
142138
this.Write(context, keyValues, generated, ruleSet, importSet);
143139
}
144140

RelaxVersioner.Core/Writers/TextReplaceProvider.cs

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ void Replace(TextReader tr, TextWriter tw)
7272
}
7373
else
7474
{
75+
if (context.IsQuietOnStandardOutput)
76+
{
77+
return;
78+
}
79+
7580
using var tr = context.ReplaceInputPath is { } rip ?
7681
new StreamReader(rip, Encoding.UTF8, true) :
7782
Console.In;

RelaxVersioner.Core/Writers/TextWriteProvider.cs

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ void Write(TextWriter tw, bool emitEol)
6464
}
6565
else
6666
{
67+
if (context.IsQuietOnStandardOutput)
68+
{
69+
return;
70+
}
71+
6772
var tw = Console.Out;
6873
Write(tw, true);
6974
}

RelaxVersioner/Program.cs

+28-23
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ public static async Task<int> Main(string[] args)
2727
{
2828
var processor = new Processor(logger);
2929
var languages = string.Join("|", processor.Languages);
30+
var verbose = false;
3031

3132
var context = new ProcessorContext
3233
{
34+
IsDryRun = false,
3335
Language = "Text",
3436
GenerateStatic = true,
3537
TextFormat = "{versionLabel}",
@@ -42,7 +44,12 @@ public static async Task<int> Main(string[] args)
4244

4345
var options = new OptionSet
4446
{
45-
{ "language=", $"target language [{languages}]", v => context.Language = v },
47+
{ "l|language=", $"target language [{languages}]", v =>
48+
{
49+
context.Language = v;
50+
verbose = true;
51+
}
52+
},
4653
{ "namespace=", "applying namespace", v => context.Namespace = v },
4754
{ "tfm=", "target framework moniker definition (TargetFramework)", v => context.TargetFramework = v },
4855
{ "tfid=", "target framework identity definition (TargetFrameworkIdentifier)", v => context.TargetFrameworkIdentity = v },
@@ -90,7 +97,9 @@ public static async Task<int> Main(string[] args)
9097
context.OutputPath = "package.json";
9198
}
9299
},
100+
{ "quiet", "quiet on stdout", _ => context.IsQuietOnStandardOutput = true },
93101
{ "dryrun", "dryrun mode", _ => context.IsDryRun = true },
102+
{ "verbose", "verbose mode", _ => verbose = true },
94103
{ "launchDebugger", "Launch debugger", _ => launchDebugger = true },
95104
{ "help", "help", v => help = v != null },
96105
};
@@ -112,6 +121,11 @@ public static async Task<int> Main(string[] args)
112121
logger.Error("");
113122
return 1;
114123
}
124+
125+
if (!verbose)
126+
{
127+
logger.SetImportance(LogImportance.Ignore);
128+
}
115129

116130
context.ProjectDirectory = trails[0];
117131

@@ -122,29 +136,20 @@ public static async Task<int> Main(string[] args)
122136
ResultWriter.Write(resultPath!, result);
123137
}
124138

125-
if (context.Language switch
126-
{
127-
"Text" => context.IsDryRun,
128-
"Replace" => context.IsDryRun,
129-
"NPM" => context.IsDryRun,
130-
_ => true,
131-
})
132-
{
133-
var dryrunDisplay = context.IsDryRun ?
134-
" (dryrun)" : string.Empty;
135-
var languageDisplay = context.IsDryRun ?
136-
string.Empty : $"Language={context.Language}, ";
137-
var tfmDisplay = context.IsDryRun ?
138-
string.Empty : $"TFM={context.TargetFramework}, ";
139+
var dryrunDisplay = context.IsDryRun ?
140+
" (dryrun)" : string.Empty;
141+
var languageDisplay = context.IsDryRun ?
142+
string.Empty : $"Language={context.Language}, ";
143+
var tfmDisplay = (context.IsDryRun || string.IsNullOrWhiteSpace(context.TargetFramework)) ?
144+
string.Empty : $"TFM={context.TargetFramework}, ";
139145

140-
logger.Message(
141-
LogImportance.High,
142-
"Generated versions code{0}: {1}{2}Version={3}",
143-
dryrunDisplay,
144-
languageDisplay,
145-
tfmDisplay,
146-
result.Version);
147-
}
146+
logger.Message(
147+
LogImportance.High,
148+
"Generated versions code{0}: {1}{2}Version={3}",
149+
dryrunDisplay,
150+
languageDisplay,
151+
tfmDisplay,
152+
result.Version);
148153
}
149154
catch (Exception ex)
150155
{

RelaxVersioner/build/RelaxVersioner.targets

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
</ItemGroup>
157157

158158
<Exec WorkingDirectory="$(RelaxVersionerToolingDir)"
159-
Command="$(RelaxVersionerToolingRuntimeName)&quot;$(RelaxVersionerToolingPath)&quot; $(_RVB_LaunchDebuggerOption) --language=&quot;$(RelaxVersionerLanguage)&quot; --namespace=&quot;$(RelaxVersionerNamespace)&quot; --tfm=&quot;$(_RVB_TargetFramework)&quot; --tfid=&quot;$(_RVB_TargetFrameworkIdentifier)&quot; --tfv=&quot;$(_RVB_TargetFrameworkVersion)&quot; --tfp=&quot;$(_RVB_TargetFrameworkProfile)&quot; --genStatic=&quot;$(RelaxVersionerGenerateStatic)&quot; --buildIdentifier=&quot;$(RelaxVersionerBuildIdentifier)&quot; --propertiesPath=&quot;$(RelaxVersionerPropertiesPath)&quot; --outputPath=@(_RVB_OutputPath->'&quot;%(FullPath)&quot;',' ') --resultPath=&quot;$(RelaxVersionerResultPath)&quot; &quot;$(MSBuildProjectFullPath)&quot;" />
159+
Command="$(RelaxVersionerToolingRuntimeName)&quot;$(RelaxVersionerToolingPath)&quot; $(_RVB_LaunchDebuggerOption) --verbose --language=&quot;$(RelaxVersionerLanguage)&quot; --namespace=&quot;$(RelaxVersionerNamespace)&quot; --tfm=&quot;$(_RVB_TargetFramework)&quot; --tfid=&quot;$(_RVB_TargetFrameworkIdentifier)&quot; --tfv=&quot;$(_RVB_TargetFrameworkVersion)&quot; --tfp=&quot;$(_RVB_TargetFrameworkProfile)&quot; --genStatic=&quot;$(RelaxVersionerGenerateStatic)&quot; --buildIdentifier=&quot;$(RelaxVersionerBuildIdentifier)&quot; --propertiesPath=&quot;$(RelaxVersionerPropertiesPath)&quot; --outputPath=@(_RVB_OutputPath->'&quot;%(FullPath)&quot;',' ') --resultPath=&quot;$(RelaxVersionerResultPath)&quot; &quot;$(MSBuildProjectFullPath)&quot;" />
160160

161161
<ItemGroup>
162162
<FileWrites Include="$(RelaxVersionerResultPath)" />
@@ -328,7 +328,7 @@
328328
</ItemGroup>
329329

330330
<Exec WorkingDirectory="$(RelaxVersionerToolingDir)"
331-
Command="$(RelaxVersionerToolingRuntimeName)&quot;$(RelaxVersionerToolingPath)&quot; $(_RVB_LaunchDebuggerOption) --buildIdentifier=&quot;$(RelaxVersionerBuildIdentifier)&quot; --namespace=&quot;$(RelaxVersionerNamespace)&quot; --tfm=&quot;$(_RVB_TargetFramework)&quot; --tfid=&quot;$(_RVB_TargetFrameworkIdentifier)&quot; --tfv=&quot;$(_RVB_TargetFrameworkVersion)&quot; --tfp=&quot;$(_RVB_TargetFrameworkProfile)&quot; --genStatic=&quot;$(RelaxVersionerGenerateStatic)&quot; --propertiesPath=&quot;$(RelaxVersionerPropertiesPath)&quot; --resultPath=&quot;$(RelaxVersionerResultPath)&quot; &quot;$(MSBuildProjectFullPath)&quot;" />
331+
Command="$(RelaxVersionerToolingRuntimeName)&quot;$(RelaxVersionerToolingPath)&quot; $(_RVB_LaunchDebuggerOption) --quiet --buildIdentifier=&quot;$(RelaxVersionerBuildIdentifier)&quot; --namespace=&quot;$(RelaxVersionerNamespace)&quot; --tfm=&quot;$(_RVB_TargetFramework)&quot; --tfid=&quot;$(_RVB_TargetFrameworkIdentifier)&quot; --tfv=&quot;$(_RVB_TargetFrameworkVersion)&quot; --tfp=&quot;$(_RVB_TargetFrameworkProfile)&quot; --genStatic=&quot;$(RelaxVersionerGenerateStatic)&quot; --propertiesPath=&quot;$(RelaxVersionerPropertiesPath)&quot; --resultPath=&quot;$(RelaxVersionerResultPath)&quot; &quot;$(MSBuildProjectFullPath)&quot;" />
332332

333333
<ItemGroup>
334334
<FileWrites Include="$(RelaxVersionerResultPath)" />

0 commit comments

Comments
 (0)