Skip to content

Commit 0915a84

Browse files
committed
Introduce GlobalCommand to indicate some commands alwasy be available
Closes gh-967 See gh-962 gh-963
1 parent 3856f4b commit 0915a84

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.grails.cli.profile
17+
18+
import groovy.transform.CompileStatic
19+
20+
/**
21+
* A marker interface that indicates that this command could be used in or out a project
22+
*
23+
* @author Michael Yan
24+
* @since 2023.3.0
25+
*/
26+
@CompileStatic
27+
interface GlobalCommand extends Command {
28+
29+
}

grace-shell/src/main/groovy/org/grails/cli/profile/commands/HelpCommand.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.grails.cli.profile.Command
2525
import org.grails.cli.profile.CommandArgument
2626
import org.grails.cli.profile.CommandDescription
2727
import org.grails.cli.profile.ExecutionContext
28+
import org.grails.cli.profile.GlobalCommand
2829
import org.grails.cli.profile.Profile
2930
import org.grails.cli.profile.ProfileCommand
3031
import org.grails.cli.profile.ProfileRepository
@@ -178,7 +179,7 @@ grace [environment]* [target] [arguments]*'
178179
}
179180
else {
180181
commands = CommandRegistry.findCommands(profileRepository).findAll { Command cmd ->
181-
!(cmd instanceof ProjectCommand)
182+
(cmd instanceof GlobalCommand) || !(cmd instanceof ProjectCommand)
182183
}
183184
}
184185
if (showAll) {

grace-shell/src/main/groovy/org/grails/cli/profile/commands/ListPluginsCommand.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import grails.build.logging.GrailsConsole
2121
import org.grails.cli.profile.Command
2222
import org.grails.cli.profile.CommandDescription
2323
import org.grails.cli.profile.ExecutionContext
24+
import org.grails.cli.profile.GlobalCommand
2425
import org.grails.cli.profile.ProjectCommand
2526

2627
/**
@@ -30,7 +31,7 @@ import org.grails.cli.profile.ProjectCommand
3031
* @since 2023.3.0
3132
*/
3233
@CompileStatic
33-
class ListPluginsCommand implements Command, ProjectCommand {
34+
class ListPluginsCommand implements Command, GlobalCommand, ProjectCommand {
3435

3536
public static final String PLUGIN_REPO_URL = 'https://repo1.maven.org/maven2/org/graceframework/plugins'
3637
private static final List<String> EXCLUDES = ['asset-pipeline-core', 'asset-pipeline-gradle', 'views-gradle']

grace-shell/src/main/groovy/org/grails/cli/profile/commands/ListProfilesCommand.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package org.grails.cli.profile.commands
1818
import groovy.transform.CompileStatic
1919

2020
import grails.build.logging.GrailsConsole
21-
21+
import grails.util.BuildSettings
2222
import org.grails.cli.profile.Command
2323
import org.grails.cli.profile.CommandDescription
2424
import org.grails.cli.profile.ExecutionContext
25+
import org.grails.cli.profile.GlobalCommand
2526
import org.grails.cli.profile.Profile
2627
import org.grails.cli.profile.ProfileRepository
2728
import org.grails.cli.profile.ProfileRepositoryAware
@@ -35,7 +36,7 @@ import org.grails.cli.profile.ProjectCommand
3536
* @since 3.0
3637
*/
3738
@CompileStatic
38-
class ListProfilesCommand implements Command, ProjectCommand, ProfileRepositoryAware {
39+
class ListProfilesCommand implements Command, GlobalCommand, ProjectCommand, ProfileRepositoryAware {
3940

4041
final String name = 'list-profiles'
4142
final CommandDescription description = new CommandDescription(name, 'Lists the available profiles', 'grace list-profiles')
@@ -47,7 +48,7 @@ class ListProfilesCommand implements Command, ProjectCommand, ProfileRepositoryA
4748
List<Profile> allProfiles = profileRepository.allProfiles.sort { Profile p -> p.name}
4849
GrailsConsole console = executionContext.console
4950
console.log('-' * 100)
50-
console.log('Available Profiles')
51+
console.log(BuildSettings.GRAILS_APP_DIR_PRESENT ? 'Used Profiles' : 'Available Profiles')
5152
console.log('-' * 100)
5253
for (Profile p in allProfiles) {
5354
console.log("* ${p.name.padRight(30)} ${p.version.padRight(20)} ${p.description}")

grace-shell/src/main/groovy/org/grails/cli/profile/commands/PluginInfoCommand.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.grails.build.parsing.CommandLine
2323
import org.grails.cli.profile.Command
2424
import org.grails.cli.profile.CommandDescription
2525
import org.grails.cli.profile.ExecutionContext
26+
import org.grails.cli.profile.GlobalCommand
2627
import org.grails.cli.profile.ProjectCommand
2728

2829
/**
@@ -31,7 +32,7 @@ import org.grails.cli.profile.ProjectCommand
3132
* @author Michael Yan
3233
* @since 2023.3.0
3334
*/
34-
class PluginInfoCommand implements Command, ProjectCommand {
35+
class PluginInfoCommand implements Command, GlobalCommand, ProjectCommand {
3536

3637
public static final String PLUGIN_REPO_URL = 'https://repo1.maven.org/maven2/org/graceframework/plugins'
3738
public static final String NAME = 'plugin-info'

grace-shell/src/main/groovy/org/grails/cli/profile/commands/ProfileInfoCommand.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.grails.cli.profile.Command
2424
import org.grails.cli.profile.CommandDescription
2525
import org.grails.cli.profile.ExecutionContext
2626
import org.grails.cli.profile.Feature
27+
import org.grails.cli.profile.GlobalCommand
2728
import org.grails.cli.profile.Profile
2829
import org.grails.cli.profile.ProfileRepository
2930
import org.grails.cli.profile.ProfileRepositoryAware
@@ -39,7 +40,7 @@ import org.grails.config.CodeGenConfig
3940
* @since 3.1
4041
*/
4142
@CompileStatic
42-
class ProfileInfoCommand extends ArgumentCompletingCommand implements ProjectCommand, ProfileRepositoryAware {
43+
class ProfileInfoCommand extends ArgumentCompletingCommand implements GlobalCommand, ProjectCommand, ProfileRepositoryAware {
4344

4445
public static final String NAME = 'profile-info'
4546

0 commit comments

Comments
 (0)