Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Sources/GlassCLI/main.swift8// Module : GlassCLI9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import GlassCLICore4344// Run the command in a task so that Ctrl-C can cancel it: the file transaction then rolls back before exit.45let work = Task {46 await CLI.run(47 arguments: Array(CommandLine.arguments.dropFirst()),48 currentDirectory: URL(fileURLWithPath: FileManager.default.currentDirectoryPath),49 environment: ProcessInfo.processInfo.environment50 )51}5253signal(SIGINT, SIG_IGN)54signal(SIGTERM, SIG_IGN)55let interrupt = DispatchSource.makeSignalSource(signal: SIGINT, queue: .global())56let terminate = DispatchSource.makeSignalSource(signal: SIGTERM, queue: .global())57interrupt.setEventHandler { work.cancel() }58terminate.setEventHandler { work.cancel() }59interrupt.resume()60terminate.resume()6162let outcome = await work.value63FileHandle.standardOutput.write(Data(outcome.standardOutput.utf8))64FileHandle.standardError.write(Data(outcome.standardError.utf8))65exit(outcome.exitCode)66