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

env 无法传递参数 #128

Closed
AhJi26 opened this issue Sep 20, 2024 · 6 comments · Fixed by #129
Closed

env 无法传递参数 #128

AhJi26 opened this issue Sep 20, 2024 · 6 comments · Fixed by #129
Labels

Comments

@AhJi26
Copy link
Contributor

AhJi26 commented Sep 20, 2024

作者你好,我更新了最新版本的fy后遇到了shebang无法传递参数的问题,输出如下

❯ fy hello
/usr/bin/env: ‘node --no-deprecation’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

我修改了/usr/lib/node_modules/fanyi/bin/fanyi.js的shebang,去除了--no-deprecation参数,可以正常运行但每次都会输出模块弃用warning导致排版混乱。
似乎shebang中的env无法传递正确传递参数,或许可以修改为其他传递参数的方式或者禁用warning?

平台:archlinux, linux 6.10.10,node 22.9.0

Copy link

maige-app bot commented Sep 20, 2024

你好,感谢你提交这个问题。看起来这是一个与 shebang 传递参数相关的问题。你可以尝试以下解决方案:

  1. 修改 shebang 行,去掉 --no-deprecation 参数,但这会导致模块弃用警告。
  2. 使用 node 命令行参数来运行脚本,例如:node --no-deprecation /path/to/fanyi.js
  3. 修改代码以禁用特定的弃用警告,可以在代码中添加以下行:
    process.noDeprecation = true;

请尝试这些方法,看看是否能解决你的问题。如果问题仍然存在,请告诉我们。

From Maige. How's my driving?

Copy link
Contributor

gitauto-ai bot commented Sep 20, 2024

Welcome to GitAuto! 🎉
Click the checkbox below to generate a PR!

  • Generate PR

@AhJi26, You have 5 requests left in this cycle which refreshes on 2024-10-06 01:47:00+00:00.
If you have any questions or concerns, please contact us at info@gitauto.ai.

Copy link

你好,感谢你反馈这个问题。

你提到的 shebang 无法传递参数的问题已经记录在 Issue #128 中。这个问题可能是由于 env 命令在传递参数时的限制导致的。

目前有两个临时解决方案:

  1. 修改 /usr/lib/node_modules/fanyi/bin/fanyi.js 的 shebang,去除 --no-deprecation 参数,但这会导致每次运行时输出模块弃用警告。
  2. 使用其他方式传递参数或者禁用警告。

我们会尽快调查并修复这个问题。如果你有进一步的建议或需要更多帮助,请随时 @ 我。

感谢你的耐心等待。

Copy link

dosubot bot commented Sep 20, 2024

@AhJi26 你好!我是一个可以帮助你解决bug、回答问题并成为贡献者的机器人。在等待人类维护者的期间,我可以为你提供帮助。

我发现了一个类似的已关闭问题:使用报错,该问题通过一个 pull request 解决:fix: ignore punycode module is deprecated warning in node 22 [1]

要解决 env 无法传递参数的问题,可以修改 /usr/lib/node_modules/fanyi/bin/fanyi.js 中的 shebang 行,将其改为:

#!/usr/bin/env -S node --no-deprecation

这样可以使用 -S 选项来正确分割参数。以下是修改后的 shebang 行在上下文中的示例:

#!/usr/bin/env -S node --no-deprecation

const { Command } = require('commander');
const chalk = require('chalk');
const updateNotifier = require('update-notifier');
const pkg = require('../package.json');
const config = require('../lib/config');
const { searchList } = require('../lib/searchHistory');

updateNotifier({ pkg }).notify();
const program = new Command();

program
  .name(pkg.name)
  .description(pkg.description)
  .version(pkg.version)
  .action(() => {
    // 如果输入是 "fanyi",没有参数,则忽略
    if (process.argv.length > 2) {
      return runFY();
    }
  });

program
  .command('config')
  .description('设置全局选项')
  .addCommand(
    new Command('list').description('查看配置项').action(async () => {
      const options = await config.load();
      console.log(`${chalk.gray(config.getConfigPath())}`);
      console.log();
      for (const [key, value] of Object.entries(options)) {
        console.log(`${chalk.cyan(key)}: ${chalk.yellow(value)}`);
      }
    }),
  )
  .addCommand(
    new Command('set')
      .description('设置配置项')
      .argument('<key>', '配置项键名')
      .argument('<value>', '配置项值')
      .action(async (key, value) => {
        const options = {};
        if (key === 'GROQ_API_KEY') {
          options[key] = value;
        } else {
          options[key] = value === 'true' ? true : value === 'false' ? false : value;
        }
        await config.write(options);
      }),
  );

program
  .command('list')
  .option('-d, --someDay <char>', '查看指定某天的查询记录')
  .option('-r, --recentDays [number]', '查看最近几天内的数据', 0)
  .option('-all --show-file [boolean]', '查看全部数据,即单词存放的位置', false)
  .action((args) => {
    searchList(args);
  });

program.on('--help', () => {
  console.log('');
  console.log(chalk.gray('示例:'));
  console.log(`${chalk.cyan('  $ ')}fanyi word`);
  console.log(`${chalk.cyan('  $ ')}fanyi world peace`);
  console.log(`${chalk.cyan('  $ ')}fanyi chinglish`);
  console.log(`${chalk.cyan('  $ ')}fanyi config set color true`);
  console.log(`${chalk.cyan('  $ ')}fanyi config set iciba true`);
  console.log(`${chalk.cyan('  $ ')}fanyi config set groq true`);
  console.log(`${chalk.cyan('  $ ')}fanyi config set GROQ_API_KEY your_api_key_here`);
  console.log(`${chalk.cyan('  $ ')}fanyi config list`);
  console.log('');
});

program.parse(process.argv);
if (!process.argv.slice(2).length) {
  program.help();
}

async function runFY(options = {}) {
  const defaultOptions = await config.load();
  const mergedOptions = { ...defaultOptions, ...options };
  const fanyi = require('..');
  fanyi(program.args.join(' '), mergedOptions);
}

这样可以禁用弃用警告并确保参数正确传递 [2]

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the bug label Sep 20, 2024
@AhJi26
Copy link
Contributor Author

AhJi26 commented Sep 20, 2024

已提pr #129

Copy link
Contributor

gitauto-ai bot commented Sep 20, 2024

Sorry, we have an error. Please try again.

Have feedback or need help?
Feel free to email info@gitauto.ai.

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

Successfully merging a pull request may close this issue.

2 participants