-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathInitCommand.cs
More file actions
60 lines (50 loc) · 2.3 KB
/
InitCommand.cs
File metadata and controls
60 lines (50 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.CommandLineUtils;
namespace Microsoft.Web.LibraryManager.Tools.Commands
{
/// <summary>
/// Defines the libman init command, to allow users to create a libman.json file in the current directory.
/// </summary>
internal class InitCommand : BaseCommand
{
public InitCommand(IHostEnvironment hostEnvironment, bool throwOnUnexpectedArg = true)
: base(throwOnUnexpectedArg, "init", Resources.Text.InitCommandDesc, hostEnvironment)
{
}
/// <summary>
/// Option to allow users to specify the default provider for the libman.json
/// </summary>
public CommandOption DefaultProvider { get; private set; }
/// <summary>
/// Option to allow users to specify the default destination for the libman.json
/// </summary>
public CommandOption DefaultDestination { get; private set; }
/// <summary>
/// Option to use all the default choices silently
/// </summary>
public CommandOption UseDefault { get; private set; }
public override BaseCommand Configure(CommandLineApplication parent)
{
base.Configure(parent);
DefaultProvider = Option("--default-provider|-p", Resources.Text.DefaultProviderOptionDesc, CommandOptionType.SingleValue);
DefaultDestination = Option("--default-destination|-d", Resources.Text.DefaultDestinationOptionDesc, CommandOptionType.SingleValue);
UseDefault = Option("--useDefault|-y", Resources.Text.UseDefault, CommandOptionType.NoValue);
return this;
}
protected async override Task<int> ExecuteInternalAsync()
{
string defaultProvider = DefaultProvider.Value();
if (string.IsNullOrEmpty(defaultProvider) && UseDefault.HasValue())
{
defaultProvider = Settings.DefaultProvider;
}
await CreateManifestAsync(defaultProvider, DefaultDestination.Value(), Settings, DefaultProvider.LongName, CancellationToken.None);
return 0;
}
}
}