public class Foo : Gtk.Application {
    private static bool print_version;
    private const OptionEntry[] option_entries = {
        { "version", 'v', 0, OptionArg.NONE, ref print_version, N_("Print version information and exit"), null },
        { null },
    };
    
    public Foo () {
        Object (application_id: "org.foo.bar");
    }

    protected override void activate () {
        stdout.printf ("activated...\n");
    }

    protected override bool local_command_line ([CCode (array_length = false, array_null_terminated = true)] ref unowned string[] arguments, out int exit_status) {
        var option_context = new OptionContext ();

        option_context.add_main_entries (option_entries, "gettext");
        option_context.add_group (Gtk.get_option_group (true));

        // Workaround related to bug report 642885
        unowned string[] args = arguments;
            
        try {
            option_context.parse (ref args);
        } catch (OptionError e) {
            exit_status = 1;
            return true;
        }

        if (print_version) {
            print ("print version\n");
            exit_status = 0;
            return true;
        }

        return base.local_command_line (ref arguments, out exit_status);
    }
}

int main (string[] args) {
    var app = new Foo ();
    return app.run (args);
}

// $ valac local_command.vala --pkg gio-2.0 --pkg gtk+-3.0 -X -DGETTEXT_PACKAGE=\""gettext"\" --target-glib 2.38

