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,106 @@ 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 (
74+ const entry of walk ( datadir ( ) . string , { includeDirs : false } )
75+ ) {
76+ if ( entry . name === "dev.pkgx.activated" ) {
77+ const partial_path = new Path ( entry . path ) . parent ( ) . relative ( {
78+ to : datadir ( ) ,
79+ } ) ;
80+ console . log ( `/${ partial_path } ` ) ;
81+ }
82+ }
83+ break ;
84+
85+ case undefined :
86+ {
87+ const cwd = Path . cwd ( ) ;
88+ const { pkgs } = await sniff ( cwd ) ;
89+ if (
90+ datadir ( ) . join ( cwd . string . slice ( 1 ) , "dev.pkgx.activated" ) . isFile ( )
91+ ) {
92+ console . log (
93+ "%cactive" ,
94+ "color: green" ,
95+ pkgs . map ( utils . pkg . str ) . join ( " " ) ,
96+ ) ;
97+ } else if ( pkgs . length > 0 ) {
98+ console . log (
99+ "%cinactive" ,
100+ "color: red" ,
101+ pkgs . map ( utils . pkg . str ) . join ( " " ) ,
102+ ) ;
103+ } else {
104+ console . log ( "%cno keyfiles found" , "color: red" ) ;
105+ }
106+ }
107+ break ;
108+
109+ case "off" : {
110+ let dir = Path . cwd ( ) ;
111+ while ( dir . string != "/" ) {
112+ const f = datadir ( ) . join ( dir . string . slice ( 1 ) , "dev.pkgx.activated" )
113+ . isFile ( ) ;
114+ if ( f ) {
115+ f . rm ( ) ;
116+ console . log ( "%cdeactivated" , "color: green" , dir . string ) ;
117+ Deno . exit ( 0 ) ;
118+ }
119+ dir = dir . parent ( ) ;
120+ }
121+ console . error ( "%cno devenv found" , "color: red" ) ;
122+ Deno . exit ( 1 ) ;
123+ break ;
124+ }
125+
64126 default : {
65- const cwd = Path . cwd ( ) . join ( subcommand as string ) ;
66- await dump ( cwd , { dryrun, quiet } ) ;
127+ if ( Deno . stdout . isTerminal ( ) ) {
128+ const cwd = Path . cwd ( ) . join ( subcommand as string ) ;
129+ const { pkgs } = await sniff ( cwd ) ;
130+ if ( pkgs . length > 0 ) {
131+ datadir ( ) . join ( cwd . string . slice ( 1 ) ) . mkdir ( "p" ) . join (
132+ "dev.pkgx.activated" ,
133+ ) . touch ( ) ;
134+ console . log (
135+ "%cactived" ,
136+ "color: green" ,
137+ pkgs . map ( utils . pkg . str ) . join ( " " ) ,
138+ ) ;
139+ } else {
140+ console . error ( "%cno keyfiles found" , "color: red" ) ;
141+ Deno . exit ( 1 ) ;
142+ }
143+ } else {
144+ const cwd = Path . cwd ( ) . join ( subcommand as string ) ;
145+ await dump ( cwd , { dryrun, quiet } ) ;
146+ }
67147 }
68148 }
69149}
0 commit comments