mirror of https://github.com/Icinga/icinga2.git
Hide attributes in command auto-completion which cannot be set
refs #7403
This commit is contained in:
parent
00cb1ca971
commit
9f7c97051e
|
@ -26,7 +26,7 @@ set(base_SOURCES
|
||||||
application.cpp application.thpp array.cpp configerror.cpp console.cpp context.cpp
|
application.cpp application.thpp array.cpp configerror.cpp console.cpp context.cpp
|
||||||
convert.cpp debuginfo.cpp dictionary.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
|
convert.cpp debuginfo.cpp dictionary.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
|
||||||
exception.cpp fifo.cpp filelogger.cpp filelogger.thpp json.cpp logger.cpp logger.thpp
|
exception.cpp fifo.cpp filelogger.cpp filelogger.thpp json.cpp logger.cpp logger.thpp
|
||||||
netstring.cpp networkstream.cpp object.cpp objectlock.cpp process.cpp
|
netstring.cpp networkstream.cpp object.cpp objectlock.cpp primitivetype.cpp process.cpp
|
||||||
ringbuffer.cpp scriptfunction.cpp scriptfunctionwrapper.cpp
|
ringbuffer.cpp scriptfunction.cpp scriptfunctionwrapper.cpp
|
||||||
scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
|
scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
|
||||||
statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp
|
statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp
|
||||||
|
|
|
@ -20,10 +20,13 @@
|
||||||
#include "base/array.hpp"
|
#include "base/array.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include "base/debug.hpp"
|
#include "base/debug.hpp"
|
||||||
|
#include "base/primitivetype.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
REGISTER_PRIMITIVE_TYPE(Array);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restrieves a value from an array.
|
* Restrieves a value from an array.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,10 +20,13 @@
|
||||||
#include "base/dictionary.hpp"
|
#include "base/dictionary.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include "base/debug.hpp"
|
#include "base/debug.hpp"
|
||||||
|
#include "base/primitivetype.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
REGISTER_PRIMITIVE_TYPE(Dictionary);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares dictionary keys using the less operator.
|
* Compares dictionary keys using the less operator.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.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. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "base/primitivetype.hpp"
|
||||||
|
|
||||||
|
using namespace icinga;
|
||||||
|
|
||||||
|
REGISTER_PRIMITIVE_TYPE(int);
|
||||||
|
REGISTER_PRIMITIVE_TYPE(double);
|
||||||
|
REGISTER_PRIMITIVE_TYPE(bool);
|
||||||
|
|
||||||
|
PrimitiveType::PrimitiveType(const String& name)
|
||||||
|
: m_Name(name)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
String PrimitiveType::GetName(void) const
|
||||||
|
{
|
||||||
|
return m_Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Type *PrimitiveType::GetBaseType(void) const
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PrimitiveType::GetAttributes(void) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PrimitiveType::GetFieldId(const String& name) const
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Field PrimitiveType::GetFieldInfo(int id) const
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid field ID.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int PrimitiveType::GetFieldCount(void) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.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. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef PRIMITIVETYPE_H
|
||||||
|
#define PRIMITIVETYPE_H
|
||||||
|
|
||||||
|
#include "base/i2-base.hpp"
|
||||||
|
#include "base/type.hpp"
|
||||||
|
#include "base/initialize.hpp"
|
||||||
|
|
||||||
|
namespace icinga
|
||||||
|
{
|
||||||
|
|
||||||
|
class I2_BASE_API PrimitiveType : public Type
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PrimitiveType(const String& name);
|
||||||
|
|
||||||
|
virtual String GetName(void) const;
|
||||||
|
virtual const Type *GetBaseType(void) const;
|
||||||
|
virtual int GetAttributes(void) const;
|
||||||
|
virtual int GetFieldId(const String& name) const;
|
||||||
|
virtual Field GetFieldInfo(int id) const;
|
||||||
|
virtual int GetFieldCount(void) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
String m_Name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define REGISTER_PRIMITIVE_TYPE(type) \
|
||||||
|
namespace { namespace UNIQUE_NAME(prt) { \
|
||||||
|
void RegisterPrimitiveType ## type(void) \
|
||||||
|
{ \
|
||||||
|
icinga::Type *t = new PrimitiveType(#type); \
|
||||||
|
icinga::Type::Register(t); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
INITIALIZE_ONCE(RegisterPrimitiveType ## type); \
|
||||||
|
} }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* PRIMITIVETYPE_H */
|
|
@ -19,11 +19,14 @@
|
||||||
|
|
||||||
#include "base/string.hpp"
|
#include "base/string.hpp"
|
||||||
#include "base/value.hpp"
|
#include "base/value.hpp"
|
||||||
|
#include "base/primitivetype.hpp"
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
REGISTER_PRIMITIVE_TYPE(String);
|
||||||
|
|
||||||
const String::SizeType String::NPos = std::string::npos;
|
const String::SizeType String::NPos = std::string::npos;
|
||||||
|
|
||||||
String::String(void)
|
String::String(void)
|
||||||
|
|
|
@ -35,15 +35,18 @@ enum FieldAttribute
|
||||||
FAConfig = 1,
|
FAConfig = 1,
|
||||||
FAState = 2
|
FAState = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Type;
|
||||||
|
|
||||||
struct Field
|
struct Field
|
||||||
{
|
{
|
||||||
int ID;
|
int ID;
|
||||||
|
const Type *FType;
|
||||||
const char *Name;
|
const char *Name;
|
||||||
int Attributes;
|
int Attributes;
|
||||||
|
|
||||||
Field(int id, const char *name, int attributes)
|
Field(int id, const Type *type, const char *name, int attributes)
|
||||||
: ID(id), Name(name), Attributes(attributes)
|
: ID(id), FType(type), Name(name), Attributes(attributes)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -105,14 +108,14 @@ struct FactoryHelper
|
||||||
|
|
||||||
#define REGISTER_TYPE(type) \
|
#define REGISTER_TYPE(type) \
|
||||||
namespace { namespace UNIQUE_NAME(rt) { \
|
namespace { namespace UNIQUE_NAME(rt) { \
|
||||||
void RegisterType(void) \
|
void RegisterType ## type(void) \
|
||||||
{ \
|
{ \
|
||||||
icinga::Type *t = new TypeImpl<type>(); \
|
icinga::Type *t = new TypeImpl<type>(); \
|
||||||
t->SetFactory(FactoryHelper<type>().GetFactory()); \
|
t->SetFactory(FactoryHelper<type>().GetFactory()); \
|
||||||
icinga::Type::Register(t); \
|
icinga::Type::Register(t); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
INITIALIZE_ONCE(RegisterType); \
|
INITIALIZE_ONCE(RegisterType ## type); \
|
||||||
} }
|
} }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,10 @@ std::vector<String> icinga::GetFieldCompletionSuggestions(const Type *type, cons
|
||||||
if (!(field.Attributes & FAConfig))
|
if (!(field.Attributes & FAConfig))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (field.FType != Type::GetByName("int") && field.FType != Type::GetByName("double")
|
||||||
|
&& field.FType != Type::GetByName("bool") && field.FType != Type::GetByName("String"))
|
||||||
|
continue;
|
||||||
|
|
||||||
String fname = field.Name;
|
String fname = field.Name;
|
||||||
|
|
||||||
if (fname == "__name" || fname == "templates" || fname == "type")
|
if (fname == "__name" || fname == "templates" || fname == "type")
|
||||||
|
|
|
@ -253,8 +253,16 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
|
||||||
|
|
||||||
size_t num = 0;
|
size_t num = 0;
|
||||||
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
||||||
|
std::string ftype = it->Type;
|
||||||
|
|
||||||
|
if (ftype.find("::Ptr") == ftype.size() - strlen("::Ptr"))
|
||||||
|
ftype = ftype.substr(0, ftype.size() - strlen("::Ptr"));
|
||||||
|
|
||||||
|
if (it->Attributes & FAEnum)
|
||||||
|
ftype = "int";
|
||||||
|
|
||||||
std::cout << "\t\t\t" << "case " << num << ":" << std::endl
|
std::cout << "\t\t\t" << "case " << num << ":" << std::endl
|
||||||
<< "\t\t\t\t" << "return Field(" << num << ", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
|
<< "\t\t\t\t" << "return Field(" << num << ", Type::GetByName(\"" << ftype << "\"), \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue