Files
santa/Source/santactl/SNTCommandController.h
Russell Hancox dc692c8256 Project: Move tests with the code they're testing (#343)
Add helper to make declaring unit tests easier
Add unit_tests test_suite containing all unit tests
Fix reload rule
Update to workspace-relative header locations that were missed before
2019-02-06 15:09:09 -05:00

67 lines
2.3 KiB
Objective-C

/// Copyright 2015 Google Inc. All rights reserved.
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
#import <Foundation/Foundation.h>
#import "Source/santactl/SNTCommand.h"
@class MOLXPCConnection;
///
/// Responsible for maintaining the list of available commands by name, printing their help text
/// when requested and launching them when requested. All of the methods in this class are
/// class methods because the @c registerCommand:named: method is called by the @c +load method
/// of each command class and so we cannot rely on its instantiation.
///
@interface SNTCommandController : NSObject
///
/// Register a new command with the specified name. Do not use this directly, use the
/// @c REGISTER_COMMAND_NAME macro instead.
///
+ (void)registerCommand:(Class<SNTCommandProtocol>)command named:(NSString *)name;
///
/// @return a usage string listing all of the available commands
///
+ (NSString *)usage;
///
/// @return the descriptive text for the given command, if it exists
///
+ (NSString *)helpForCommandWithName:(NSString *)command;
///
/// @return YES if @c commandName exists.
///
+ (BOOL)hasCommandWithName:(NSString *)commandName;
///
/// Runs the given command with the given arguments.
///
/// @param commandName the name of a previously-registered command
/// @param arguments an array of arguments to pass to the command
///
+ (void)runCommandWithName:(NSString *)commandName arguments:(NSArray *)arguments;
@end
///
/// This macro registers a given class as a command with the name passed in @c a (which must be an
/// NSString). Must be placed just inside the implementation of the class, ideally at the top.
/// The class that uses this macro must implement the @c SNTCommand protcol.
///
#define REGISTER_COMMAND_NAME(a) \
+ (void)load { [SNTCommandController registerCommand:[self class] named:a]; }