summaryrefslogtreecommitdiff
path: root/TAO/CIAO/DAnCE/RepositoryManager/Options.cpp
blob: 6503e01aa3e8206969c5a5a1df459b5af3dbf21c (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// $Id$

// Options.cpp,v Stoyan

#include "ace/Get_Opt.h"
#include "ace/ARGV.h"
#include "Options.h"


bool
Options::parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("n:l:u:ifdsTNa"));

  int c;

  while ((c = get_opt ()) != -1)
    switch (c)
      {
      case 'i':
        this->install_ = true;
        break;
      case 'd':
        this->delete_ = true;
        break;
      case 'f':
        this->find_ = true;
        break;
      case 's':
        this->shutdown_ = true;
        break;
      case 'n':
        this->name_ = get_opt.opt_arg ();
        break;
      case 'l':
        this->path_ = get_opt.opt_arg ();
        break;
      case 'u':
        this->uuid_ = get_opt.opt_arg ();
        break;
      case 'N':
        this->all_names_ = true;
        break;
      case 'T':
        this->all_types_ = true;
        break;
      case 'a':
        this->names_by_type_ = true;
        break;
        // Usage fallthrough.
      default:
        this->usage ();
        return false;
      }

  if ((this->name_ == "")
    && (this->shutdown_ == false)
    && (this->uuid_ == "")
    && (this->all_names_ == false)
    && (this->all_types_ == false))
  {
    this->usage ();
    return false;
  }
  else if (this->name_ != "")
  {
    if (!(this->install_ || this->find_ || this->delete_))
  {
    this->usage ();
    return false;
  }
    else if (this->install_ && this->path_ == "")
  {
    this->usage ();
    return false;
  }
  }
  else if (this->uuid_ != "")
  {
    if (!this->find_ && !this->names_by_type_)
  {
    this->usage ();
    return false;
  }
  }

  return true;
}

/// @todo Exit is not nice, return -1 so that the caller can do something and
/// we don't exit abruptly
void Options::usage (void)
{
  ACE_DEBUG ((LM_INFO, "OPTIONS: -s <shutdown> -n <:name> [-i <install> -l <:path>] \
              [-d <delete>] [-f <find>] [-u <:uuid> [-a <names by type>] ] \
              [-N <all names>] [-T <all types>]\n"));
}

Options::Options (void)
  : name_ (""),
    uuid_ (""),
    path_ (""),
    delete_ (false),
    install_ (false),
    find_ (false),
    all_names_ (false),
    all_types_ (false),
    names_by_type_ (false),
    shutdown_ (false)
{
}