#!/usr/bin/env node

/**
 * inject-token.js
 * 
 * 将 gateway.auth.token 设置为 "aiyiran"。
 * 
 * 入口: myclaw token
 */

const { readConfig, writeConfig } = require('../find-config');

function run(cliArgs) {
  let configPath;
  try {
    ({ configPath } = readConfig());
  } catch (err) {
    console.error('❌ ' + err.message);
    process.exit(1);
  }

  console.log('→ 找到配置: ' + configPath);

  const { config } = readConfig();

  if (!config.gateway) config.gateway = {};
  if (!config.gateway.auth) config.gateway.auth = {};

  config.gateway.auth.token = "aiyiran";

  writeConfig(config, configPath);

  console.log('✅ Token 已设置为 "aiyiran"');
  console.log('');
}

module.exports = { run };
