Skip to content

Commit 7ccf39f

Browse files
authored
Merge pull request #14 from nop77svk/feature/gold-plating
🛠 CLI version info read from project assemblies
2 parents a19e940 + 1ad11da commit 7ccf39f

File tree

5 files changed

+232
-174
lines changed

5 files changed

+232
-174
lines changed
Lines changed: 192 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,192 @@
1-
namespace jwl.console;
2-
using jwl.core;
3-
using jwl.infra;
4-
5-
public class ScrollingConsoleProcessFeedback
6-
: ICoreProcessFeedback, IDisposable
7-
{
8-
public Action? FeedbackDelay { get; init; } = null;
9-
10-
private bool _isDisposed;
11-
private int _numberOfWorklogsToInsert = 0;
12-
private int _numberOfWorklogsToDelete = 0;
13-
14-
public ScrollingConsoleProcessFeedback(int totalSteps)
15-
{
16-
}
17-
18-
public void Dispose()
19-
{
20-
// note: Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
21-
Dispose(disposing: true);
22-
GC.SuppressFinalize(this);
23-
}
24-
25-
public void FillJiraWithWorklogsStart()
26-
{
27-
_numberOfWorklogsToInsert = 0;
28-
_numberOfWorklogsToDelete = 0;
29-
Console.Error.Write(@"Filling Jira with worklogs...");
30-
}
31-
32-
public void FillJiraWithWorklogsSetTarget(int numberOfWorklogsToInsert, int numberOfWorklogsToDelete)
33-
{
34-
_numberOfWorklogsToInsert = numberOfWorklogsToInsert;
35-
_numberOfWorklogsToDelete = numberOfWorklogsToDelete;
36-
Console.Error.Write($"\rFilling Jira with worklogs (+{_numberOfWorklogsToInsert}/-{_numberOfWorklogsToDelete})...");
37-
}
38-
39-
public void FillJiraWithWorklogsProcess(MultiTaskStats progress)
40-
{
41-
Console.Error.Write($"\rFilling Jira with worklogs (+{_numberOfWorklogsToInsert}/-{_numberOfWorklogsToDelete})... {ProgressPercentageAsString(progress)}");
42-
}
43-
44-
public void FillJiraWithWorklogsEnd()
45-
{
46-
_numberOfWorklogsToInsert = 0;
47-
_numberOfWorklogsToDelete = 0;
48-
Console.Error.WriteLine();
49-
}
50-
51-
public void NoExistingWorklogsToDelete()
52-
{
53-
}
54-
55-
public void NoFilesOnInput()
56-
{
57-
Console.Error.WriteLine(@"Note: No files on input - no work to be done");
58-
}
59-
60-
public void NoWorklogsToFill()
61-
{
62-
Console.Error.WriteLine(@"Note: Empty files on input - no work to be done");
63-
}
64-
65-
public void OverallProcessStart()
66-
{
67-
Console.Error.WriteLine(@"Jira Worklogger CLI 2024.2.0"); // 2do! read from assembly
68-
Console.Error.WriteLine(@"by Peter H., practically copyleft"); // 2do! read from assembly
69-
Console.Error.WriteLine(new string('-', Console.WindowWidth - 1));
70-
}
71-
72-
public void OverallProcessEnd()
73-
{
74-
Console.Error.WriteLine(@"DONE");
75-
}
76-
77-
public void PreloadAvailableWorklogTypesStart()
78-
{
79-
Console.Error.Write(@"Preloading available worklog types from server...");
80-
}
81-
82-
public void PreloadAvailableWorklogTypesEnd()
83-
{
84-
Console.Error.WriteLine(@" OK");
85-
}
86-
87-
public void PreloadUserInfoStart(string userName)
88-
{
89-
Console.Error.Write($"Preloading user \"{userName}\" info from server...");
90-
}
91-
92-
public void PreloadUserInfoEnd()
93-
{
94-
Console.Error.WriteLine(@" OK");
95-
}
96-
97-
public void ReadCsvInputStart()
98-
{
99-
Console.Error.Write(@"Reading input files...");
100-
}
101-
102-
public void ReadCsvInputSetTarget(int numberOfInputFiles)
103-
{
104-
Console.Error.Write($"\rReading {numberOfInputFiles} input files...");
105-
}
106-
107-
public void ReadCsvInputProcess(MultiTaskStats progress)
108-
{
109-
Console.Error.Write($"\rReading {progress.Total} input files... {ProgressPercentageAsString(progress)}");
110-
}
111-
112-
public void ReadCsvInputEnd()
113-
{
114-
Console.Error.WriteLine();
115-
}
116-
117-
public void RetrieveWorklogsForDeletionStart()
118-
{
119-
Console.Error.Write(@"Retrieving list of worklogs to be deleted...");
120-
}
121-
122-
public void RetrieveWorklogsForDeletionSetTarget(int count)
123-
{
124-
Console.Error.Write($"\rRetrieving list of worklogs ({count} Jira issues) to be deleted...");
125-
}
126-
127-
public void RetrieveWorklogsForDeletionProcess(MultiTaskStats progress)
128-
{
129-
throw new NotImplementedException(@"--- checkpoint ---");
130-
}
131-
132-
public void RetrieveWorklogsForDeletionEnd()
133-
{
134-
Console.Error.WriteLine(" OK");
135-
}
136-
137-
protected static string ProgressPercentageAsString(MultiTaskStats progress)
138-
{
139-
string result;
140-
141-
if (progress.Total <= 0)
142-
{
143-
result = @"done";
144-
}
145-
else
146-
{
147-
result = progress.SucceededPct.ToString("P");
148-
149-
if (progress.ErredSoFar > 0)
150-
{
151-
result += " OK, " + progress.ErredSoFarPct.ToString("P") + " failed";
152-
}
153-
}
154-
155-
return result;
156-
}
157-
158-
protected virtual void Dispose(bool disposing)
159-
{
160-
if (!_isDisposed)
161-
{
162-
if (disposing)
163-
{
164-
}
165-
166-
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
167-
// TODO: set large fields to null
168-
_isDisposed = true;
169-
}
170-
}
171-
}
1+
namespace jwl.console;
2+
using jwl.core;
3+
using jwl.infra;
4+
using System.Reflection;
5+
6+
public class ScrollingConsoleProcessFeedback
7+
: ICoreProcessFeedback, IDisposable
8+
{
9+
public Action? FeedbackDelay { get; init; } = null;
10+
11+
private bool _isDisposed;
12+
private int _numberOfWorklogsToInsert = 0;
13+
private int _numberOfWorklogsToDelete = 0;
14+
15+
public ScrollingConsoleProcessFeedback(int totalSteps)
16+
{
17+
}
18+
19+
public void Dispose()
20+
{
21+
// note: Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
22+
Dispose(disposing: true);
23+
GC.SuppressFinalize(this);
24+
}
25+
26+
public void FillJiraWithWorklogsStart()
27+
{
28+
_numberOfWorklogsToInsert = 0;
29+
_numberOfWorklogsToDelete = 0;
30+
Console.Error.Write(@"Filling Jira with worklogs...");
31+
}
32+
33+
public void FillJiraWithWorklogsSetTarget(int numberOfWorklogsToInsert, int numberOfWorklogsToDelete)
34+
{
35+
_numberOfWorklogsToInsert = numberOfWorklogsToInsert;
36+
_numberOfWorklogsToDelete = numberOfWorklogsToDelete;
37+
Console.Error.Write($"\rFilling Jira with worklogs (+{_numberOfWorklogsToInsert}/-{_numberOfWorklogsToDelete})...");
38+
}
39+
40+
public void FillJiraWithWorklogsProcess(MultiTaskStats progress)
41+
{
42+
Console.Error.Write($"\rFilling Jira with worklogs (+{_numberOfWorklogsToInsert}/-{_numberOfWorklogsToDelete})... {ProgressPercentageAsString(progress)}");
43+
}
44+
45+
public void FillJiraWithWorklogsEnd()
46+
{
47+
_numberOfWorklogsToInsert = 0;
48+
_numberOfWorklogsToDelete = 0;
49+
Console.Error.WriteLine();
50+
}
51+
52+
public void NoExistingWorklogsToDelete()
53+
{
54+
}
55+
56+
public void NoFilesOnInput()
57+
{
58+
Console.Error.WriteLine(@"Note: No files on input - no work to be done");
59+
}
60+
61+
public void NoWorklogsToFill()
62+
{
63+
Console.Error.WriteLine(@"Note: Empty files on input - no work to be done");
64+
}
65+
66+
public void OverallProcessStart()
67+
{
68+
Assembly exe = Assembly.GetExecutingAssembly();
69+
object productName = exe.CustomAttributes
70+
.First(x => x.AttributeType == typeof(AssemblyTitleAttribute))
71+
.ConstructorArguments.First().Value
72+
?? "<unknown product>";
73+
object cliVersion = exe.CustomAttributes
74+
.First(x => x.AttributeType == typeof(AssemblyFileVersionAttribute))
75+
.ConstructorArguments.First().Value
76+
?? "?.?.?";
77+
78+
Assembly? core = Assembly.GetAssembly(typeof(JwlCoreProcess));
79+
object coreVersion = core?.CustomAttributes
80+
.First(x => x.AttributeType == typeof(AssemblyFileVersionAttribute))
81+
.ConstructorArguments.First().Value
82+
?? "?.?.?";
83+
object coreCopyright = core?.CustomAttributes
84+
.First(x => x.AttributeType == typeof(AssemblyCopyrightAttribute))
85+
.ConstructorArguments.First().Value
86+
?? "copy rights undetermined";
87+
88+
Console.Error.WriteLine($"{productName} {cliVersion} (core {coreVersion})");
89+
Console.Error.WriteLine($"by Peter H., {coreCopyright}");
90+
Console.Error.WriteLine(new string('-', Console.WindowWidth - 1));
91+
}
92+
93+
public void OverallProcessEnd()
94+
{
95+
Console.Error.WriteLine(@"DONE");
96+
}
97+
98+
public void PreloadAvailableWorklogTypesStart()
99+
{
100+
Console.Error.Write(@"Preloading available worklog types from server...");
101+
}
102+
103+
public void PreloadAvailableWorklogTypesEnd()
104+
{
105+
Console.Error.WriteLine(@" OK");
106+
}
107+
108+
public void PreloadUserInfoStart(string userName)
109+
{
110+
Console.Error.Write($"Preloading user \"{userName}\" info from server...");
111+
}
112+
113+
public void PreloadUserInfoEnd()
114+
{
115+
Console.Error.WriteLine(@" OK");
116+
}
117+
118+
public void ReadCsvInputStart()
119+
{
120+
Console.Error.Write(@"Reading input files...");
121+
}
122+
123+
public void ReadCsvInputSetTarget(int numberOfInputFiles)
124+
{
125+
Console.Error.Write($"\rReading {numberOfInputFiles} input files...");
126+
}
127+
128+
public void ReadCsvInputProcess(MultiTaskStats progress)
129+
{
130+
Console.Error.Write($"\rReading {progress.Total} input files... {ProgressPercentageAsString(progress)}");
131+
}
132+
133+
public void ReadCsvInputEnd()
134+
{
135+
Console.Error.WriteLine();
136+
}
137+
138+
public void RetrieveWorklogsForDeletionStart()
139+
{
140+
Console.Error.Write(@"Retrieving list of worklogs to be deleted...");
141+
}
142+
143+
public void RetrieveWorklogsForDeletionSetTarget(int count)
144+
{
145+
Console.Error.Write($"\rRetrieving list of worklogs ({count} Jira issues) to be deleted...");
146+
}
147+
148+
public void RetrieveWorklogsForDeletionProcess(MultiTaskStats progress)
149+
{
150+
throw new NotImplementedException(@"--- checkpoint ---");
151+
}
152+
153+
public void RetrieveWorklogsForDeletionEnd()
154+
{
155+
Console.Error.WriteLine(" OK");
156+
}
157+
158+
protected static string ProgressPercentageAsString(MultiTaskStats progress)
159+
{
160+
string result;
161+
162+
if (progress.Total <= 0)
163+
{
164+
result = @"done";
165+
}
166+
else
167+
{
168+
result = progress.SucceededPct.ToString("P");
169+
170+
if (progress.ErredSoFar > 0)
171+
{
172+
result += " OK, " + progress.ErredSoFarPct.ToString("P") + " failed";
173+
}
174+
}
175+
176+
return result;
177+
}
178+
179+
protected virtual void Dispose(bool disposing)
180+
{
181+
if (!_isDisposed)
182+
{
183+
if (disposing)
184+
{
185+
}
186+
187+
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
188+
// TODO: set large fields to null
189+
_isDisposed = true;
190+
}
191+
}
192+
}

jwl.console/jwl.console.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<Nullable>enable</Nullable>
1818
<Product>Jira Worklogger</Product>
1919
<AssemblyTitle>Jira Worklogger CLI</AssemblyTitle>
20-
<Authors>Peter Hraško</Authors>
20+
<AssemblyVersion>1.2.0</AssemblyVersion>
21+
<Authors>Peter Hraško</Authors>
2122
<Company>Open source community</Company>
2223
<Copyright>Practically copyleft</Copyright>
2324
<NoWarn>1701;1702;AD0001;NETSDK1182</NoWarn>

jwl.core/JwlCoreProcess.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class JwlCoreProcess : IDisposable
1515
public ICoreProcessFeedback? Feedback { get; init; }
1616
public ICoreProcessInteraction _interaction { get; }
1717

18+
public Version? ExeVersion => AssemblyVersioning.GetExeVersion();
19+
public Version? CoreVersion => AssemblyVersioning.GetCoreVersion(typeof(JwlCoreProcess));
20+
1821
private bool _isDisposed;
1922

2023
private AppConfig _config;

0 commit comments

Comments
 (0)