Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get hooks to work #71

Closed
FokkeZB opened this issue Nov 8, 2013 · 8 comments
Closed

Cannot get hooks to work #71

FokkeZB opened this issue Nov 8, 2013 · 8 comments

Comments

@FokkeZB
Copy link
Contributor

FokkeZB commented Nov 8, 2013

I'm writing a hook as apart of TiNy so you can also do:

titanium ios

This should be doable using the hooks, just like the included tisdk3fixes hook manipulates the commands given.

However, when I add the hook it doesn't log anything when I call ti build or ti create etc. When I call ti or ti config it does log.

Are the hooks not implemented for build and create yet?

@cb1kenobi
Copy link
Contributor

You do not want to use a hook to do this. Hooks and commands are different. To create a command, simply create a directory with a javascript file (your command). Then add the directory to the CLI's "paths.commands" config settings. Refer to slide 17 for a nudge in the right direction: http://www.slideshare.net/cb1kenobi/titanium-cli-32-ti-appcamp2-1122013.

@FokkeZB
Copy link
Contributor Author

FokkeZB commented Nov 14, 2013

TiNy is already pluggable as a command, but I want to also make it a hook so you can do:

ti "Fokke Zandbergen (HSHD7DD)" "12312-32ASDFS-123132DFSS" myrecipe

I'm sure there's a hook to transform the arguments? I see similar happening in the tisdk3fixes hook.

@cb1kenobi
Copy link
Contributor

Hmm... the CLI doesn't have a hook for you to hook into that would allow you modify the command line arguments. The first hook to fire is "cli:command-loaded" and that's done after all the argument parsing passes have completed.

The only thing you can do is hook into "cli:command-loaded" and overwrite the parsed cli.argv values.

tisdk3fixes isn't modifying arguments. It modifies the TiSDK 3.0 and 3.1 iOS build options to force the deploy-type to "production" for dist-appstore and dist-adhoc builds. What happened was there was a bug in the CLI that I fixed in June 2013 that revealed another bug in each Titanium 3.0.x and 3.1.x SDK. tisdk3fixes forces the correct deploy type so that Titanium CLI 3.2 can call a Titanium SDK 3.1.x (or older) build.

@FokkeZB
Copy link
Contributor Author

FokkeZB commented Nov 14, 2013

Logging all different, events I think I can better use cli:post-validate. If I use cli:command-loaded and use an unknown option, the CLI never emits the event. I'l play around with it ;)

@FokkeZB
Copy link
Contributor Author

FokkeZB commented Nov 14, 2013

I have the following test hook:

var _ = require('underscore');

exports.cliVersion = '>=3.X';

exports.init = function(logger, config, cli) {
    _.each(['cli:command-not-found', 'cli:command-loaded', 'cli:pre-validate', 'cli:post-validate', 'cli:pre-execute', 'cli:post-execute'], function(hook) {
        cli.on(hook, function(e, next) {
            console.log(hook);
            next();
        });
    });
};

When I run ti help I get:

~  ti help
cli:command-loaded
cli:pre-validate
Titanium Command-Line Interface, CLI version 3.2.0, Titanium SDK version 3.2.0.v20131110134044
Copyright (c) 2012-2013, Appcelerator, Inc.  All Rights Reserved.

Please report bugs to http://jira.appcelerator.org/

cli:post-validate
cli:pre-execute
Usage: titanium <command> [options]

   [cut]

cli:post-execute

But when I run ti build I get:

ti build
Titanium Command-Line Interface, CLI version 3.2.0, Titanium SDK version 3.2.0.v20131110134044
Copyright (c) 2012-2013, Appcelerator, Inc.  All Rights Reserved.

Please report bugs to http://jira.appcelerator.org/

Target platform to build for:
 1)  android
 2)  blackberry
 3)  ios
 4)  mobileweb
 5)  tizen
Enter # or platform name:

Question: Is there not any hook executed for ti build? What I would like is hook/hack this command, parse any arguments such as UUIDs, names, TiNy recipes etc and then continue the build with altered options.

@cb1kenobi
Copy link
Contributor

--platform is special and baked into the CLI. If you are running a command that has a --platform option, but --platform is omitted, then the CLI will prompt for the platform immediately. The old CLI use to defer --platform option processing until the command's options are being validated. The new CLI requires --platform to be defined before the validation process begins.

@FokkeZB
Copy link
Contributor Author

FokkeZB commented Nov 16, 2013

Aha! I've created a JIRA ticket requesting a hook that executes before the process' argv are parsed by the CLI:

https://jira.appcelerator.org/browse/TC-3292

@cb1kenobi
Copy link
Contributor

Brilliant! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants