2017-08-04 5 views
0

Vorpal.jsを使用してCLIツールを構築しました。これは最終的にAPIエンドポイントに対してHTTP要求を実行します。vorpalアクション中に別の関数を呼び出す

私は質問をしてデータ入力を検証していますが、入力が終わったら、要求された回答からエンドポイントURLを契約する別のメソッドを呼び出すことになります。ここで

は私のコードです:

function apiEndpoint (env) { 
    if (env === 'INT') { 
     return API_ENDPOINT_INT; 
    } else if (env === 'TEST') { 
     return API_ENDPOINT_TEST; 
    } else if (env === 'LIVE') { 
     return API_ENDPOINT_LIVE 
    } 
} 

function constructRequestURL (params) { 
    let API_ENDPOINT = apiEndpoint(params.env); 

    let requestURL = `${API_GATEWAY}${API_ENDPOINT}?asset_uri=${params.asset_uri}&${site_name}&${asset_type}&${event_type}` 

    return requestURL; 
} 

vorpal 
    .command('render') 
    .option('--dave') 
    .action(function (args, cb) { 
     const self = this; 
     this.prompt(questions) 
     .then (function (result) { 
     // self.log(`Okay, here are you answers ${JSON.stringify(result)}`); 
      let requestURL = constructRequestURL(result); 
      self.log(`Request URL: ${requestURL}`); 
      cb(); 
     }) 
    }) 


vorpal 
    .delimiter('AMP ReRenderer$') 
    .show(); 

このコメント行は

// self.log(`Okay, here are you answers ${JSON.stringify(result)}`); 

どのように今まで何も起こらないとCLIツールは、単に存在constructUrl関数を呼び出すときに動作します。

私はそれが範囲の問題かもしれないと思いますか?

答えて

1

いいえ、おそらくサイレントに失敗しています。約束の上に常にcatchがあることを確認してください。

vorpal 
    .command('render') 
    .option('--dave') 
    .action(function (args, cb) { 
     const self = this; 
     this.prompt(questions) 
     .then (function (result) { 
     // self.log(`Okay, here are you answers ${JSON.stringify(result)}`); 
      let requestURL = constructRequestURL(result); 
      self.log(`Request URL: ${requestURL}`); 
      cb(); 
     }).catch(err => { 
     self.log(err); 
     cb(); 
     }); 
    }) 
+0

すぐそこに、完全に忘れました。変数が定義されていませんでした!ありがとう。 – chinds

+0

それはうまく動作します。 – dthree

関連する問題