Skip to content

Commit f548d8a

Browse files
committed
release 1.1.3 => new '-d' --dontoverwrite option
1 parent 4b1e8ec commit f548d8a

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

CopyDeployer.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ internal class CopyDeployer
3333
public CopyDeployer(CopyDeployerOptions options)
3434
{
3535
_options = options;
36-
if (_options.Summary)
37-
_options.Quiet = true;
38-
if (_options.Quiet)
39-
_options.Verbose = false;
4036
}
4137

4238
public int Execute()
@@ -48,17 +44,24 @@ public int Execute()
4844
Quiet("Path to copy from is not a valid directory: {0}", from);
4945
return 2;
5046
}
51-
if (!Directory.Exists(Path.GetDirectoryName(to))) {
47+
if (!Directory.Exists(ParentDir(to))) {
5248
Quiet("Path to deploy into is not a valid directory: {0}", to);
5349
return 3;
5450
}
55-
Quiet("Deploying from {0} into {1}", from, to);
56-
if (_options.CleanTarget && Directory.Exists(to)) {
57-
Quiet("Removing previous content at: {0}", to);
58-
Directory.Delete(to, true);
51+
if (_options.DontOverWrite && Directory.Exists(to)) {
52+
Summary("Skipping existing target directory: {0}", to);
53+
} else {
54+
Quiet("Deploying from {0} into {1}", from, to);
55+
if (_options.CleanTarget && Directory.Exists(to)) {
56+
Quiet("Removing previous content at: {0}", to);
57+
Directory.Delete(to, true);
58+
}
59+
DeployDir(from, to);
60+
if (_options.CleanTarget)
61+
Summary("{0} files copied", _filesCopied);
62+
else
63+
Summary("{0} files copied, {1} files skipped", _filesCopied, _filesSkipped);
5964
}
60-
DeployDir(from, to);
61-
Summary("{0} files copied, {1} files skipped", _filesCopied, _filesSkipped);
6265
return 0;
6366
} catch (Exception e) {
6467
Quiet("Exception: {0}", e);
@@ -70,6 +73,11 @@ public int Execute()
7073
private int _filesSkipped = 0;
7174
private CopyDeployerOptions _options;
7275

76+
private static string ParentDir(string to)
77+
{
78+
return Path.GetDirectoryName(to);
79+
}
80+
7381
private void DeployDir(string from, string to)
7482
{
7583
if (!Directory.Exists(to))
@@ -105,22 +113,22 @@ private byte[] HashFile(string file)
105113
return md5.ComputeHash(stream);
106114
}
107115

108-
private void Summary(string format, params object[] parameters)
116+
private void Quiet(string format, params object[] parameters)
109117
{
110-
WriteLine(_options.Summary || !_options.Quiet, format, parameters);
118+
WriteLineIf(!_options.Quiet, format, parameters);
111119
}
112120

113-
private void Quiet(string format, params object[] parameters)
121+
private void Summary(string format, params object[] parameters)
114122
{
115-
WriteLine(!_options.Quiet, format, parameters);
123+
WriteLineIf(_options.Summary || !_options.Quiet, format, parameters);
116124
}
117125

118126
private void Verbose(string format, params object[] parameters)
119127
{
120-
WriteLine(_options.Verbose, format, parameters);
128+
WriteLineIf(_options.Verbose, format, parameters);
121129
}
122130

123-
private void WriteLine(bool condition, string format, object[] parameters)
131+
private void WriteLineIf(bool condition, string format, object[] parameters)
124132
{
125133
if (condition)
126134
Console.WriteLine(string.Format(format, parameters));

CopyDeployerOptions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,28 @@ public CopyDeployerOptions(string[] args)
3838
[Option("Clean target directory", "clean", ShortForm = 'c')]
3939
public bool CleanTarget { get; set; }
4040

41+
[Option("Do not overwrite if there is a target directory", "dontoverwrite", ShortForm = 'd')]
42+
public bool DontOverWrite { get; set; }
43+
4144
[Option("Path to {directory} to copy from (default: current directory)", "from", ShortForm = 'f')]
4245
public string From { get; set; }
4346

4447
public bool IsOk
4548
{
4649
get
4750
{
51+
if (CleanTarget && DontOverWrite) {
52+
ReportError(-1, "You can't ask to clean the target directory and not to overwrite it at the same time!!!");
53+
return false;
54+
}
4855
if (string.IsNullOrWhiteSpace(FirstArgument)) {
4956
DoHelp();
5057
return false;
5158
}
59+
if (Summary)
60+
Quiet = true;
61+
if (Quiet)
62+
Verbose = false;
5263
return true;
5364
}
5465
}
@@ -80,7 +91,6 @@ protected override void InitializeOtherDefaults()
8091
{
8192
base.InitializeOtherDefaults();
8293
From = Directory.GetCurrentDirectory();
83-
Verbose = false;
8494
}
8595
}
8696
}

Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
[assembly: AssemblyTrademark("")]
3434
[assembly: AssemblyCulture("")]
3535
[assembly: ComVisible(false)]
36-
[assembly: AssemblyVersion("1.1.2")]
37-
[assembly: AssemblyFileVersion("1.1.2")]
38-
[assembly: AssemblyInformationalVersion("1.1.2")]
36+
[assembly: AssemblyVersion("1.1.3")]
37+
[assembly: AssemblyFileVersion("1.1.3")]
38+
[assembly: AssemblyInformationalVersion("1.1.3")]
3939
[assembly: UsageComplement("<path of directory to deploy into>")]
4040
[assembly: ReportBugsTo("https://github.com/managed-commons/cpdeploy/issues")]
4141
[assembly: License(LicenseType.MIT)]

0 commit comments

Comments
 (0)