-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add (non-working) .NET Core CLI commands
Part of #3925
- Loading branch information
Showing
28 changed files
with
1,020 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.EntityFrameworkCore.Design.Internal; | ||
using Microsoft.DotNet.Cli.Utils; | ||
using JetBrains.Annotations; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Commands | ||
{ | ||
public class ConsoleCommandLogger : CommandLogger | ||
{ | ||
public ConsoleCommandLogger([NotNull] string name) | ||
: base(name) | ||
{ | ||
} | ||
|
||
protected override void WriteDebug(string message) | ||
=> Reporter.Verbose.WriteLine(message.Bold().Black()); | ||
|
||
protected override void WriteError(string message) | ||
=> Reporter.Error.WriteLine(message.Bold().Red()); | ||
|
||
protected override void WriteInformation(string message) | ||
=> Reporter.Error.WriteLine(message); | ||
|
||
protected override void WriteTrace(string message) | ||
=> Reporter.Verbose.WriteLine(message.Bold().Black()); | ||
|
||
protected override void WriteWarning(string message) | ||
=> Reporter.Error.WriteLine(message.Bold().Yellow()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Commands | ||
{ | ||
public class DatabaseCommand | ||
{ | ||
public static void Configure([NotNull] CommandLineApplication command) | ||
{ | ||
command.Description = "Commands to manage your database"; | ||
|
||
command.HelpOption("-h|--help"); | ||
|
||
command.Command("update", DatabaseUpdateCommand.Configure); | ||
|
||
command.OnExecute(() => command.ShowHelp()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Commands | ||
{ | ||
public class DatabaseUpdateCommand | ||
{ | ||
public static void Configure([NotNull] CommandLineApplication command) | ||
{ | ||
command.Description = "Updates the database to a specified migration"; | ||
|
||
var migration = command.Argument( | ||
"[migration]", | ||
"The target migration. If '0', all migrations will be reverted. If omitted, all pending migrations will be applied"); | ||
|
||
var context = command.Option( | ||
"-c|--context <context>", | ||
"The DbContext to use. If omitted, the default DbContext is used"); | ||
var startupProject = command.Option( | ||
"-s|--startupProject <project>", | ||
"The startup project to use. If omitted, the current project is used."); | ||
var environment = command.Option( | ||
"-e|--environment <environment>", | ||
"The environment to use. If omitted, \"Development\" is used."); | ||
command.HelpOption("-h|--help"); | ||
|
||
command.OnExecute( | ||
() => Execute(migration.Value, context.Value(), startupProject.Value(), environment.Value())); | ||
} | ||
|
||
private static int Execute(string migration, string context, string startupProject, string environment) | ||
{ | ||
new OperationsFactory(startupProject, environment) | ||
.CreateMigrationsOperations() | ||
.UpdateDatabase(migration, context); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.