Skip to content

Commit d77e2b5

Browse files
committed
Add used options to output of code generated, issue #35
1 parent c8095fe commit d77e2b5

File tree

7 files changed

+79
-21
lines changed

7 files changed

+79
-21
lines changed

OData2Poco.CommandLine.Test/ProgramTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Text.RegularExpressions;
56
using System.Threading.Tasks;
67
using NUnit.Framework;
78
using OData2Poco.TestUtility;
@@ -403,6 +404,25 @@ public async Task Url_test(string url, string version, int n)
403404
Assert.IsTrue(output.Contains("public partial class Product")); //-v
404405

405406
}
407+
408+
[Test]
409+
[Category("code_header")]
410+
[TestCaseSource(typeof(TestSample), nameof(TestSample.FileCases))]
411+
[TestCaseSource(typeof(TestSample), nameof(TestSample.UrlNorthwindCases))]
412+
public async Task CodeHeaderTest(string url, string version, int n)
413+
{
414+
//Arrange
415+
var a = $"-r {url} -v --include Category";
416+
//Act
417+
var tuble = await RunCommand(a);
418+
var output = tuble.Item2;
419+
//Assert
420+
var line = $"// Service Url: {url}";
421+
Assert.IsTrue(output.Contains(line));
422+
423+
Assert.IsTrue(output.Contains("// Parameters:"));
424+
Assert.IsTrue(output.Contains("// -v Verbose= True"));
425+
}
406426

407427
#region Name Case
408428

OData2Poco.Core/CommandLineUtility.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ public static List<string> GetOptions(Options option)
4141
if (!string.IsNullOrEmpty(val.ToString()))
4242
{
4343
var text = $"{shortName} {p1.p.Name}= {val} ";
44+
if (shortName.Equals("-p") || shortName.Equals("--password")) //hide password for security reason
45+
text = $"{shortName} {p1.p.Name}= ***** ";
4446
list.Add(text);
4547
}
4648
}
49+
CodeHeader.SetParameters(list);
4750
return list;
4851
}
4952

OData2PocoLib/CodeHeader.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using OData2Poco.TextTransform;
2+
using System;
3+
using System.Linq;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace OData2Poco
8+
{
9+
public class CodeHeader
10+
{
11+
static List<string> Parameters = new List<string>();
12+
public static string GetHeader(IPocoGenerator pocoGen)
13+
{
14+
var comment = @"//------------------------------------------------------------------------------
15+
// <auto-generated>
16+
// This code was generated using OData2Poco System.
17+
// Service Url: {0}
18+
// MetaData Version: {1}
19+
// Generated On: {2}
20+
// Parameters:
21+
{3}
22+
// </auto-generated>
23+
//------------------------------------------------------------------------------
24+
";
25+
26+
//The <auto-generated> tag at the start of the file
27+
var h = new FluentCsTextTemplate();
28+
var pp = Parameters.Where(x => !(x.Trim().StartsWith("-r") || x.Trim().StartsWith("--url")))
29+
.Select(x => $"// \t{x}");
30+
h.WriteLine(comment, pocoGen.MetaData.ServiceUrl, pocoGen.MetaData.MetaDataVersion,
31+
DateTimeOffset.Now.ToString("s"), string.Join(Environment.NewLine, pp));
32+
return h.ToString();
33+
}
34+
public static void SetParameters(List<string> parameters)
35+
{
36+
Parameters = new List<string>(parameters);
37+
}
38+
}
39+
}

OData2PocoLib/MetaDataReader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static async Task<MetaDataInfo> LoadMetadataAsync(OdataConnectionString o
7171
{
7272
var xml = await reader.ReadToEndAsync();
7373
metaData = LoadMetaDataFromXml(xml);
74+
metaData.ServiceUrl = odataConnString.ServiceUrl;
7475
return metaData;
7576
}
7677
}

OData2PocoLib/PocoClassGeneratorCs.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using OData2Poco.CustAttributes;
55
using OData2Poco.TextTransform;
6+
using OData2Poco;
67

78
namespace OData2Poco
89
{
@@ -169,27 +170,12 @@ internal string ReducedBaseTyp(ClassTemplate ct)
169170
reducedName = ct.BaseType.Replace(ns, "");
170171
return reducedName;
171172
}
172-
173173
private string GetHeader()
174174
{
175-
var comment = @"//------------------------------------------------------------------------------
176-
// <auto-generated>
177-
// This code was generated using OData2Poco System.
178-
// Service Url: {0}
179-
// MetaData Version: {1}
180-
// Generated On: {2}
181-
// </auto-generated>
182-
//------------------------------------------------------------------------------
183-
//";
184-
185-
//The <auto-generated> tag at the start of the file
186-
var h = new FluentCsTextTemplate();
187-
h.WriteLine(comment, _pocoGen.MetaData.ServiceUrl, _pocoGen.MetaData.MetaDataVersion,
188-
DateTimeOffset.Now.ToString("s"));
189175

190-
return h.ToString();
176+
return CodeHeader.GetHeader(_pocoGen);
191177
}
192-
178+
193179
private string UsingAssembly(List<string> nameSpaces)
194180
{
195181
var h = new FluentCsTextTemplate();

ReleaseNotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
## (Console: o2pgen / .Net Core: dotnet-o2pgen)
66

7+
8+
## Version 3.5.0
9+
**Release Date:** March 8, 2021
10+
11+
**What is new in 3.5.0:**
12+
- New Feature request: Add used options to the header of the code generated, issue [#35](https://github.com/moh-hassan/odata2poco/issues/35)
13+
- Fix of displaying serviceUrl when the source is xml file, #35.
14+
- Hide password when displaying used options for security.
15+
716
## Version 3.4.2
817
**Release Date:** Dec 21, 2020
918

appveyor.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#nuget version is nly changed by RELEASE TAG
2-
version: 3.4.2-ci-{build}
2+
version: 3.5.0-ci-{build}
33
image: Visual Studio 2019
44
pull_requests:
55
do_not_increment_build_number: false
@@ -15,12 +15,12 @@ init:
1515
try
1616
{
1717
Update-AppveyorBuild -Version $ver
18-
Write-Output "Update-AppveyorBuild Success to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Green
18+
Write-Host "Update-AppveyorBuild Success to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Green
1919
}
2020
catch
2121
{
22-
Write-Output "Update-AppveyorBuild Fail to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Red
23-
Write-Output "Exception Error: $PSItem.Exception.Message" -ForegroundColor Red
22+
Write-Host "Update-AppveyorBuild Fail to change version to TAG: '$env:APPVEYOR_REPO_TAG_NAME'" -ForegroundColor Red
23+
Write-Host "Exception Error: $PSItem.Exception.Message" -ForegroundColor Red
2424
$env:CAN_PUBLISH = $false
2525
}
2626
}

0 commit comments

Comments
 (0)