converted executable-based commands to the new command API (as "core")
This commit is contained in:
		@@ -1,3 +1,4 @@
 | 
			
		||||
// vim: filetype=cpp
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
@@ -42,9 +43,18 @@ int main(int argc, char* argv[]) {
 | 
			
		||||
 | 
			
		||||
        cmdparse.parse(argc, argv);
 | 
			
		||||
 | 
			
		||||
        for (auto item : commands::bottles_commands()) {
 | 
			
		||||
            commands::command_map[item.first] = item.second;
 | 
			
		||||
        }
 | 
			
		||||
        /*[[[cog
 | 
			
		||||
             import cog
 | 
			
		||||
 | 
			
		||||
             with open("src/modules.txt") as modules:
 | 
			
		||||
                for module in modules:
 | 
			
		||||
                    cog.out("""
 | 
			
		||||
                        for (auto item : commands::""" + module.strip() + """_commands()) {
 | 
			
		||||
                            commands::command_map[item.first] = item.second;
 | 
			
		||||
                        }
 | 
			
		||||
                    """, dedent=True, trimblanklines=True)
 | 
			
		||||
          ]]]*/
 | 
			
		||||
        //[[[end]]]
 | 
			
		||||
 | 
			
		||||
        string usercmd = command.getValue();
 | 
			
		||||
        if (commands::command_map.count(usercmd) > 0) {
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
// vim: filetype=cpp :
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
@@ -37,4 +38,20 @@ void help_command(int argc, vector<string> argv) {
 | 
			
		||||
    }
 | 
			
		||||
    cout << endl;
 | 
			
		||||
}
 | 
			
		||||
CommandFunction helpcmd = command_map["help"] = &help_command;
 | 
			
		||||
 | 
			
		||||
map<string, CommandFunction> cellar::commands::core_commands() {
 | 
			
		||||
    map<string, CommandFunction> result;
 | 
			
		||||
    /*[[[cog
 | 
			
		||||
         import cog
 | 
			
		||||
 | 
			
		||||
         with open("src/commands.txt") as commandfile:
 | 
			
		||||
            for line in commandfile:
 | 
			
		||||
                linesplit = line.strip().split(" ")
 | 
			
		||||
                name = linesplit[0]
 | 
			
		||||
                func = linesplit[1]
 | 
			
		||||
 | 
			
		||||
                cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func))
 | 
			
		||||
      ]]]*/
 | 
			
		||||
    //[[[end]]]
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										2
									
								
								src/commands.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/commands.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
version print_version
 | 
			
		||||
help help_command
 | 
			
		||||
							
								
								
									
										2
									
								
								src/modules.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/modules.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
core
 | 
			
		||||
bottles
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "cellar.hpp"
 | 
			
		||||
#include "commands.hpp"
 | 
			
		||||
#include "output.hpp"
 | 
			
		||||
#include "version.hpp"
 | 
			
		||||
@@ -41,7 +42,6 @@ string cellar::version::short_version() {
 | 
			
		||||
    //[[[end]]]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void print_version(int argc, vector<string> argv) {
 | 
			
		||||
void cellar::print_version(int argc, vector<string> argv) {
 | 
			
		||||
    cellar::output::statement(short_version());
 | 
			
		||||
}
 | 
			
		||||
cellar::commands::CommandFunction versioncmd = cellar::commands::command_map["version"] = &print_version;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user