Skip to content

Commit

Permalink
(chocolatey#179) Add confirm option to source
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCakeIsNaOH committed Nov 13, 2021
1 parent 1d663a7 commit 369ae62
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ private static void set_machine_sources(ChocolateyConfiguration config, ConfigFi
Priority = source.Priority,
BypassProxy = source.BypassProxy,
AllowSelfService = source.AllowSelfService,
VisibleToAdminsOnly = source.VisibleToAdminsOnly
VisibleToAdminsOnly = source.VisibleToAdminsOnly,
Confirm = source.Confirm
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("adminonly|admin-only",
"Visible to Administrators Only - Should this source be visible to non-administrators? Requires business edition (v1.12.2+). Defaults to false. Available in 0.10.8+.",
option => configuration.SourceCommand.VisibleToAdminsOnly = option != null)
.Add("confirm",
"Confirm - Should this source automatically run package scripts instead of prompting to confirm? Defaults to false. Available in 0.12.0+.",
option => configuration.SourceCommand.Confirm = option != null)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ public sealed class SourcesCommandConfiguration
public bool BypassProxy { get; set; }
public bool AllowSelfService { get; set; }
public bool VisibleToAdminsOnly { get; set; }
public bool Confirm { get; set; }
}

[Serializable]
Expand All @@ -484,6 +485,7 @@ public sealed class MachineSourceConfiguration
public bool BypassProxy { get; set; }
public bool AllowSelfService { get; set; }
public bool VisibleToAdminsOnly { get; set; }
public bool Confirm { get; set; }
}

[Serializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class ChocolateySource

public bool AllowSelfService { get; set; }

public bool VisibleToAdminOnly { get; set; }
public bool VisibleToAdminOnly { get; set; }

public bool Confirm { get; set; }

public int Priority { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public sealed class ConfigFileSourceSetting
[XmlAttribute(AttributeName = "certificatePassword")]
public string CertificatePassword { get; set; }

[XmlAttribute(AttributeName = "confirm")]
public bool Confirm { get; set; }

public override bool Equals(object obj)
{
// Check for null values and compare run-time types.
Expand All @@ -79,7 +82,8 @@ public override bool Equals(object obj)
&& (Password == item.Password)
&& (Priority == item.Priority)
&& (Certificate == item.Certificate)
&& (CertificatePassword == item.CertificatePassword);
&& (CertificatePassword == item.CertificatePassword)
&& (Confirm == item.Confirm);
}

public override int GetHashCode()
Expand All @@ -95,7 +99,8 @@ public override int GetHashCode()
.And(Password)
.And(Priority)
.And(Certificate)
.And(CertificatePassword);
.And(CertificatePassword)
.And(Confirm);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,21 @@ public virtual IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration
if (!configuration.QuietOutput) {
if (configuration.RegularOutput)
{
this.Log().Info(() => "{0}{1} - {2} {3}| Priority {4}|Bypass Proxy - {5}|Self-Service - {6}|Admin Only - {7}.".format_with(
this.Log().Info(() => "{0}{1} - {2} {3}| Priority {4}|Bypass Proxy - {5}|Self-Service - {6}|Admin Only - {7}|Confirm - {8}.".format_with(
source.Id,
source.Disabled ? " [Disabled]" : string.Empty,
source.Value,
(string.IsNullOrWhiteSpace(source.UserName) && string.IsNullOrWhiteSpace(source.Certificate)) ? string.Empty : "(Authenticated)",
source.Priority,
source.BypassProxy.to_string(),
source.AllowSelfService.to_string(),
source.VisibleToAdminsOnly.to_string()
source.VisibleToAdminsOnly.to_string(),
source.Confirm.to_string()
));
}
else
{
this.Log().Info(() => "{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}".format_with(
this.Log().Info(() => "{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}".format_with(
source.Id.quote_if_pipe_found(),
source.Value,
source.Disabled.to_string(),
Expand All @@ -83,7 +84,8 @@ public virtual IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration
source.Priority,
source.BypassProxy.to_string(),
source.AllowSelfService.to_string(),
source.VisibleToAdminsOnly.to_string()
source.VisibleToAdminsOnly.to_string(),
source.Confirm.to_string()
));
}
}
Expand All @@ -95,7 +97,8 @@ public virtual IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration
Priority = source.Priority,
BypassProxy = source.BypassProxy,
AllowSelfService = source.AllowSelfService,
VisibleToAdminOnly = source.VisibleToAdminsOnly
VisibleToAdminOnly = source.VisibleToAdminsOnly,
Confirm = source.Confirm
});
}
return list;
Expand All @@ -117,7 +120,8 @@ public void source_add(ChocolateyConfiguration configuration)
Priority = configuration.SourceCommand.Priority,
BypassProxy = configuration.SourceCommand.BypassProxy,
AllowSelfService = configuration.SourceCommand.AllowSelfService,
VisibleToAdminsOnly = configuration.SourceCommand.VisibleToAdminsOnly
VisibleToAdminsOnly = configuration.SourceCommand.VisibleToAdminsOnly,
Confirm = configuration.SourceCommand.Confirm
};
configFileSettings.Sources.Add(source);

Expand All @@ -136,7 +140,8 @@ public void source_add(ChocolateyConfiguration configuration)
configuration.SourceCommand.Certificate.is_equal_to(source.Certificate) &&
configuration.SourceCommand.BypassProxy == source.BypassProxy &&
configuration.SourceCommand.AllowSelfService == source.AllowSelfService &&
configuration.SourceCommand.VisibleToAdminsOnly == source.VisibleToAdminsOnly
configuration.SourceCommand.VisibleToAdminsOnly == source.VisibleToAdminsOnly &&
configuration.SourceCommand.Confirm == source.Confirm
)
{
if (!configuration.QuietOutput) this.Log().Warn(NO_CHANGE_MESSAGE);
Expand All @@ -152,6 +157,7 @@ public void source_add(ChocolateyConfiguration configuration)
source.BypassProxy = configuration.SourceCommand.BypassProxy;
source.AllowSelfService = configuration.SourceCommand.AllowSelfService;
source.VisibleToAdminsOnly = configuration.SourceCommand.VisibleToAdminsOnly;
source.Confirm = configuration.SourceCommand.Confirm;

_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
if (!configuration.QuietOutput) this.Log().Warn(() => "Updated {0} - {1} (Priority {2})".format_with(source.Id, source.Value, source.Priority));
Expand Down

0 comments on commit 369ae62

Please sign in to comment.