GOptionContex and GObject Introspection and GApplication and PEOPLE



GOptionContext is not introspectable by GObject Introspection,
and it's also not possible to cleanly add options into custom
GApplication-based application (with proper help support). I
want to make a replacement for GOptionContext - GArgContext
that is based on GObject. Maybe in the future this could also
be integrated with GApplication.

How my GArgContext will look like in the programming language:

--------------------------------------------------------------

const GArg = imports.gi.GArg;

const TRI_TRUE = 1;
const TRI_FALSE = -1;
const TRI_UNDEFINED = 0;

const CustomOption = new Lang.Class({
  Name: 'CustomOption',
  Extends: GArg.Option,

  vfunc_parse: function(text) {
    let value = new GObject.Value();
    if (text == "true")
      value.set_int(TRI_TRUE);
    else if (text == "false")
      value.set_int(TRI_FALSE);
    else if (text == "undefined";
      value.set_int(TRI_UNDEFINED);
    else
      throw /* How to throw GError??? */;
    return value;
  }
});

let main_group = new GArg.Group({
  summary: "A build system for normal, complete PEOPLE",
  footer: "Send bug reports to lamefun me gmail com"
});

main_group.append("source-dir", "S", 0, GArg.Type.STRING, "Source directory", "DIR");
main_group.append("build-dir", "B", 0, GArg.Type.STRING, "Build directory", "DIR");
main_group.append_option(new CustomOption({
  name: "tribool",
  short_name: "t",
  help: "A triboolean argument",
  metavar: "TRIBOOL"
}));

let context = new GArg.Context({
  version: "Elixir 0.1",
  main_group: main_group
});

let values = context.parse(ARGV);

if (values.has_option("source-dir"))
  print("Source directory: " + values.get_string("source-dir"));

if (values.has_option("build-dir"))
  print("Build directory: " + values.get_string("build-dir"));

if (values.has_option("tribool"))
  print("Triboolean: " + values.get_int("tribool").toString());

--------------------------------------------------------------

I already have some C code. Does my work make sense and is it
at all necessary?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]