completion.js 770 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * grunt-cli
  3. * http://gruntjs.com/
  4. *
  5. * Copyright (c) 2016 Tyler Kellen, contributors
  6. * Licensed under the MIT license.
  7. * https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT
  8. */
  9. 'use strict';
  10. // Nodejs libs.
  11. var fs = require('fs');
  12. var path = require('path');
  13. exports.print = function(name) {
  14. var code = 0;
  15. var filepath = path.join(__dirname, '../completion', name);
  16. var output;
  17. try {
  18. // Attempt to read shell completion file.
  19. output = String(fs.readFileSync(filepath));
  20. } catch (err) {
  21. code = 5;
  22. output = 'echo "Specified grunt shell auto-completion rules ';
  23. if (name && name !== 'true') {
  24. output += 'for \'' + name + '\' ';
  25. }
  26. output += 'not found."';
  27. }
  28. console.log(output);
  29. process.exit(code);
  30. };