Fawkes API  Fawkes Development Version
main.cpp
1 /***************************************************************************
2  * main.cpp - Interface generator main app
3  *
4  * Generated: Tue Oct 10 17:42:05 2006
5  * Copyright 2006 Tim Niemueller [www.niemueller.de]
6  *
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #include <string>
23 #include <cstdio>
24 #include <ctime>
25 #include <utils/system/argparser.h>
26 #include "plugin_generator.h"
27 
28 using namespace std;
29 using namespace fawkes;
30 
31 void
32 print_usage(const char *program_name)
33 {
34  printf("Usage: %s [-h] <author_name> <plugin_name> <description> <directory> \n"
35  "Example: %s \"John Doe\" robot_mover \"Move the robot a meter forward\" \n"
36  " ~/fawkes/src/plugins/robot_mover/"
37  "\n"
38  "-h Print this usage information\n\n"
39  "Generate the necessary files to build a fawkes plugin\n",
40  program_name, program_name);
41 }
42 
43 void
44 generate_plugin(std::string author_name, std::string plugin_name, std::string description, std::string directory)
45 {
46  time_t now = time(0);
47  std::string date = ctime(&now);
48  tm *time_structure = localtime(&now);
49  std::string year = std::to_string(time_structure->tm_year + 1900);
50  //TimeStructure's year is the number of years since 1900
51 
52  PluginGenerator *generator = new PluginGenerator(directory, author_name, year , date, plugin_name, description);
53  generator->generate();
54 }
55 
56 bool
57 plugin_name_valid(std::string plugin_name){
58  for (char& c : plugin_name){
59  if (isalpha(c) || c == '-' || c == '_') {
60  } else {
61  return false;
62  }
63  }
64  return true;
65 }
66 
67 int
68 main(int argc, char **argv)
69 {
70  ArgumentParser argp(argc, argv, "h");
71 
72  if ( argp.has_arg("h") ) {
73  print_usage(argv[0]);
74  exit(0);
75  }
76 
77  std::string author_name, plugin_name, description, directory;
78  if (argp.num_items() != 4) {
79  printf("ERROR: Invalid number of arguments\n");
80  print_usage(argv[0]);
81  exit(1);
82  } else if (!plugin_name_valid(argp.items()[1])) {
83  printf("ERROR: Invalid plugin name: Only alphanumerical chars allowed. \n"
84  "To separate multiple words use '-' or '_'\n");
85  exit(2);
86  }
87  else {
88  author_name = argp.items()[0];
89  plugin_name = argp.items()[1];
90  description = argp.items()[2];
91  directory = argp.items()[3];
92  generate_plugin(author_name, plugin_name, description, directory);
93  }
94 
95  return 0;
96 }
Fawkes library namespace.
STL namespace.
Parse command line arguments.
Definition: argparser.h:66
void generate()
Generator cpp and h files.
Generate basic plugins from minimal input.