33//TODO if you step into dev-dir/subdir and type `dev` does it find the root properly?
44//TODO dev off uses PWD which may not be correct if in subdir (obv)
55
6- import { Path } from "libpkgx" ;
6+ import { Path , utils } from "libpkgx" ;
77import shellcode , { datadir } from "./src/shellcode().ts" ;
88import app_version from "./src/app-version.ts" ;
99import integrate from "./src/integrate.ts" ;
1010import { parseArgs } from "jsr:@std/cli@^1/parse-args" ;
1111import dump from "./src/dump.ts" ;
1212import sniff from "./src/sniff.ts" ;
13+ import { walk } from "jsr:@std/fs@1/walk" ;
1314
1415const parsedArgs = parseArgs ( Deno . args , {
1516 alias : {
@@ -28,10 +29,13 @@ const parsedArgs = parseArgs(Deno.args, {
2829} ) ;
2930
3031if ( parsedArgs . help ) {
31- const status = await new Deno . Command ( "pkgx" , {
32- args : [ "--quiet" , "gh" , "repo" , "view" , "pkgxdev/dev" ] ,
32+ const { code } = await new Deno . Command ( "pkgx" , {
33+ args : [
34+ "glow" ,
35+ "https://raw.githubusercontent.com/pkgxdev/dev/refs/heads/main/README.md" ,
36+ ] ,
3337 } ) . spawn ( ) . status ;
34- Deno . exit ( status . code ) ;
38+ Deno . exit ( code ) ;
3539} else if ( parsedArgs . shellcode ) {
3640 console . log ( shellcode ( ) ) ;
3741} else if ( parsedArgs . version ) {
@@ -40,30 +44,84 @@ if (parsedArgs.help) {
4044 const subcommand = parsedArgs . _ [ 0 ] ;
4145 const dryrun = parsedArgs [ "dry-run" ] as boolean ;
4246 const quiet = parsedArgs [ "quiet" ] != undefined ;
47+
4348 switch ( subcommand ) {
4449 case "integrate" :
4550 await integrate ( "install" , { dryrun } ) ;
4651 break ;
52+
4753 case "deintegrate" :
4854 await integrate ( "uninstall" , { dryrun } ) ;
4955 break ;
56+
5057 case "status" :
5158 {
5259 const cwd = Path . cwd ( ) ;
5360 if (
5461 datadir ( ) . join ( cwd . string . slice ( 1 ) , "dev.pkgx.activated" ) . isFile ( )
5562 ) {
56- //FIXME probably slower than necessary
63+ //FIXME probably slower than ideal
5764 const { pkgs } = await sniff ( cwd ) ;
5865 Deno . exit ( pkgs . length == 0 ? 1 : 0 ) ;
5966 } else {
6067 Deno . exit ( 1 ) ;
6168 }
6269 }
6370 break ;
71+
72+ case "ls" :
73+ for await ( const entry of walk ( datadir ( ) . string , { includeDirs : false } ) ) {
74+ if ( entry . name === "dev.pkgx.activated" ) {
75+ const partial_path = new Path ( entry . path ) . parent ( ) . relative ( { to : datadir ( ) } ) ;
76+ console . log ( `/${ partial_path } ` ) ;
77+ }
78+ }
79+ break ;
80+
81+ case undefined : {
82+ const cwd = Path . cwd ( ) ;
83+ const { pkgs } = await sniff ( cwd ) ;
84+ if ( datadir ( ) . join ( cwd . string . slice ( 1 ) , "dev.pkgx.activated" ) . isFile ( ) ) {
85+ console . log ( "%cactive" , 'color: green' , pkgs . map ( utils . pkg . str ) . join ( " " ) ) ;
86+ } else if ( pkgs . length > 0 ) {
87+ console . log ( "%cinactive" , 'color: red' , pkgs . map ( utils . pkg . str ) . join ( " " ) ) ;
88+ } else {
89+ console . log ( "%cno keyfiles found" , 'color: red' ) ;
90+ }
91+ }
92+ break ;
93+
94+ case "off" : {
95+ let dir = Path . cwd ( ) ;
96+ while ( dir . string != "/" ) {
97+ const f = datadir ( ) . join ( dir . string . slice ( 1 ) , "dev.pkgx.activated" ) . isFile ( ) ;
98+ if ( f ) {
99+ f . rm ( ) ;
100+ console . log ( "%cdeactivated" , 'color: green' , dir . string ) ;
101+ Deno . exit ( 0 ) ;
102+ }
103+ dir = dir . parent ( ) ;
104+ }
105+ console . error ( "%cno devenv found" , 'color: red' ) ;
106+ Deno . exit ( 1 ) ;
107+ break ;
108+ }
109+
64110 default : {
65- const cwd = Path . cwd ( ) . join ( subcommand as string ) ;
66- await dump ( cwd , { dryrun, quiet } ) ;
111+ if ( Deno . stdout . isTerminal ( ) ) {
112+ const cwd = Path . cwd ( ) . join ( subcommand as string ) ;
113+ const { pkgs } = await sniff ( cwd ) ;
114+ if ( pkgs . length > 0 ) {
115+ datadir ( ) . join ( cwd . string . slice ( 1 ) ) . mkdir ( 'p' ) . join ( "dev.pkgx.activated" ) . touch ( ) ;
116+ console . log ( "%cactived" , 'color: green' , pkgs . map ( utils . pkg . str ) . join ( " " ) ) ;
117+ } else {
118+ console . error ( "%cno keyfiles found" , 'color: red' ) ;
119+ Deno . exit ( 1 ) ;
120+ }
121+ } else {
122+ const cwd = Path . cwd ( ) . join ( subcommand as string ) ;
123+ await dump ( cwd , { dryrun, quiet } ) ;
124+ }
67125 }
68126 }
69127}
0 commit comments