// cell help - Display help information for cell commands

var fd = use('fd')

var command = length(args) > 0 ? args[0] : null
var man_file = null
var stat = null
var content = null

// Display specific command help
if (command) {
  man_file = 'scripts/man/' + command + '.man'
  stat = fd.stat(man_file)
  if (stat && stat.isFile) {
    content = text(fd.slurp(man_file))
    log.console(content)
  } else {
    log.error("No help available for command: " + command)
    log.console("Run 'cell help' to see available commands.")
  }
  $stop()
}

// Display general help
man_file = 'scripts/man/cell.man'
stat = fd.stat(man_file)
if (stat && stat.isFile) {
  content = text(fd.slurp(man_file))
  log.console(content)
} else {
  // Fallback if man file doesn't exist
  log.console("cell - The Cell package manager")
  log.console("")
  log.console("Usage: cell <command> [arguments]")
  log.console("")
  log.console("Package Management:")
  log.console("  install <locator>   Install a package and its dependencies")
  log.console("  update [locator]    Update packages from remote sources")
  log.console("  remove <locator>    Remove a package from the shop")
  log.console("  add <locator>       Add a dependency to current package")
  log.console("")
  log.console("Building:")
  log.console("  build [locator]     Build dynamic libraries for packages")
  log.console("  clean [scope]       Remove build artifacts")
  log.console("")
  log.console("Linking (Local Development):")
  log.console("  link <origin> <target>  Link a package to a local path")
  log.console("  unlink <origin>         Remove a package link")
  log.console("  clone <origin> <path>   Clone and link a package locally")
  log.console("")
  log.console("Information:")
  log.console("  list [scope]        List packages and dependencies")
  log.console("  ls [locator]        List modules and actors in a package")
  log.console("  why <locator>       Show reverse dependencies")
  log.console("  search <query>      Search for packages, modules, or actors")
  log.console("")
  log.console("Diagnostics:")
  log.console("  resolve [locator]   Print fully resolved dependency closure")
  log.console("  graph [locator]     Emit dependency graph (tree, dot, json)")
  log.console("  verify [scope]      Verify integrity and consistency")
  log.console("  audit [locator]     Test-compile all scripts in package(s)")
  log.console("")
  log.console("Other:")
  log.console("  help [command]      Show help for a command")
  log.console("  version             Show cell version")
  log.console("")
  log.console("Run 'cell <command> --help' for more information on a command.")
}

$stop()
