summaryrefslogtreecommitdiffstats
path: root/src/common/cli/cli_main.h
blob: 42941add94171e98cfe1e5488af330fab4647b0d (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/***************************************************************************
 *   Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#ifndef CLI_MAIN_H
#define CLI_MAIN_H

#include "common/global/about.h"
#include "common/global/log.h"
#include "cli_global.h"

namespace CLI
{
//-----------------------------------------------------------------------------
enum Property { NoProperty = 0, HasForce = 1, HasInteractiveMode = 2 };
TQ_DECLARE_FLAGS(Properties, Property)
TQ_DECLARE_OPERATORS_FOR_FLAGS(Properties)

extern const KCmdLineOptions OPTIONS[];
//-----------------------------------------------------------------------------
struct CommandData {
  const char *name;
  int properties;
  const char *help;
};
extern const CommandData NORMAL_COMMAND_DATA[];
extern const CommandData INTERACTIVE_COMMAND_DATA[];
extern const CommandData *findCommandData(const TQString &command);
extern ExitCode findCommand(const TQString &s);
extern ExitCode commandList();

//-----------------------------------------------------------------------------
struct PropertyData
{
  const char *name, *optName, *alias, *help, *list, *listHelp;
};
extern const PropertyData PROPERTY_DATA[];
extern bool isPropertyList(const TQString &s);
extern bool isProperty(const TQString &s);
extern ExitCode propertyList();

//-----------------------------------------------------------------------------
class OptionList : public Piklab::OptionList
{
public:
  OptionList(Properties properties);
  OptionList(Properties properties, const KCmdLineOptions *options);

private:
  void init(Properties properties);
};

//-----------------------------------------------------------------------------
class MainBase : public TQObject, public Log::Base
{
Q_OBJECT
  
public:
  MainBase(Properties properties);
  virtual OptionList optionList(const char *fileDescription) const;
  virtual ExitCode doRun();
  virtual ExitCode list(const TQString &listName);
  virtual ExitCode prepareCommand(const TQString &command) = 0;
  virtual ExitCode executeCommand(const TQString &command) = 0;
  virtual ExitCode executeSetCommand(const TQString &property, const TQString &value) = 0;
  virtual TQString executeGetCommand(const TQString &property) = 0;

protected:
  Properties    _properties;
  KCmdLineArgs *_args;

private:
  virtual ExitCode prepareRun(bool &interactive) = 0;
  virtual void init();
};

} // namespace

#endif