COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/sspatch/sspatch.cpp
Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 #include <coopy/Diff.h>
00004 
00005 using namespace coopy::app;
00006 using namespace std;
00007 
00008 int main(int argc, char *argv[]) {
00009   Options opt("sspatch");
00010   int r = opt.apply(argc,argv);
00011   if (r!=0) return r;
00012 
00013   bool help = opt.checkBool("help");
00014   const vector<string>& core = opt.getCore();
00015   if ((core.size()<1 && (opt.checkString("mode")=="")) || help) {
00016     opt.beginHelp();
00017     opt.addUsage("sspatch [options] DATAFILE PATCHFILE");
00018     opt.addUsage("sspatch [options] --cmd PATCHSTRING DATAFILE");
00019     opt.addDescription("Modify a table/database/spreadsheet to integrate the changes described in a pre-computed difference.");
00020     opt.showOptions(OPTION_FOR_PATCH);
00021     opt.addExample("sspatch numbers_buggy.csv numbers_patch.tdiff",
00022                    "Apply a patch to a table. Output goes to standard output. Input file is untouched.").require("numbers_buggy.csv").require("_numbers_patch.tdiff");
00023     opt.addExample("sspatch --inplace numbers_buggy.csv numbers_patch.tdiff",
00024                    "Apply a patch to a table. Input file is modified.").require("numbers_buggy.csv").require("_numbers_patch.tdiff");
00025     opt.addExample("sspatch --tmp tmp.sqlite numbers_buggy.sqlite numbers_patch.tdiff",
00026                    "Apply a patch to a sqlite database. Input file is not modified. Space for a temporary database is needed to do this. If not supplied, sspatch will ask for it.").require("numbers_buggy.sqlite").require("_numbers_patch.tdiff");
00027     opt.addExample("sspatch - numbers_patch.tdiff < numbers_buggy.csv",
00028                    "Apply a patch to a table read from standard input.").require("numbers_buggy.csv").require("_numbers_patch.tdiff");
00029     opt.addExample("sspatch numbers_buggy.csv - < numbers_patch.tdiff",
00030                    "Apply a patch read from standard input.").require("numbers_buggy.csv").require("_numbers_patch.tdiff");
00031     opt.addExample("sspatch --cmd \"+ |two|2|\" numbers_buggy.csv",
00032                    "Add a new row to a table.").require("numbers_buggy.csv");
00033     opt.addExample("sspatch --cmd \"- |NAME=four|\" numbers.csv",
00034                    "Remove a row from a table").require("numbers.csv");
00035     opt.addExample("sspatch --cmd \"= |NAME=four|DIGIT:*->4|\" numbers_buggy.csv",
00036                    "Change the DIGIT column on a row with NAME=four.").require("numbers_buggy.csv");
00037     opt.addExample("sspatch --inplace  --table organizations \\--cmd \"+ |42|The New Organization|\" directory.sqlite","Add an organization. The specified organization ID is replaced by an autoincremented ID generated by sqlite. Use 'ssformat directory.sqlite' to view result.").require("directory.sqlite");
00038     opt.addExample("sspatch --native --inplace  --table organizations \\--cmd \"+ |42|The New Organization|\" directory.sqlite","Add an organization. The specified organization ID is used (due to --native flag). Use 'ssformat directory.sqlite' to view result.").require("directory.sqlite");
00039     opt.endHelp();
00040     return help?0:1;
00041   }
00042 
00043   Diff diff;
00044   return diff.apply(opt);
00045 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines