11import { EOL } from "os"
2+ import { Effect } from "effect"
3+ import { AppRuntime } from "@/effect/app-runtime"
24import { File } from "../../../file"
35import { bootstrap } from "../../bootstrap"
46import { cmd } from "../cmd"
@@ -15,7 +17,11 @@ const FileSearchCommand = cmd({
1517 } ) ,
1618 async handler ( args ) {
1719 await bootstrap ( process . cwd ( ) , async ( ) => {
18- const results = await File . search ( { query : args . query } )
20+ const results = await AppRuntime . runPromise (
21+ Effect . gen ( function * ( ) {
22+ return yield * File . Service . use ( ( svc ) => svc . search ( { query : args . query } ) )
23+ } ) ,
24+ )
1925 process . stdout . write ( results . join ( EOL ) + EOL )
2026 } )
2127 } ,
@@ -32,7 +38,11 @@ const FileReadCommand = cmd({
3238 } ) ,
3339 async handler ( args ) {
3440 await bootstrap ( process . cwd ( ) , async ( ) => {
35- const content = await File . read ( args . path )
41+ const content = await AppRuntime . runPromise (
42+ Effect . gen ( function * ( ) {
43+ return yield * File . Service . use ( ( svc ) => svc . read ( args . path ) )
44+ } ) ,
45+ )
3646 process . stdout . write ( JSON . stringify ( content , null , 2 ) + EOL )
3747 } )
3848 } ,
@@ -44,7 +54,11 @@ const FileStatusCommand = cmd({
4454 builder : ( yargs ) => yargs ,
4555 async handler ( ) {
4656 await bootstrap ( process . cwd ( ) , async ( ) => {
47- const status = await File . status ( )
57+ const status = await AppRuntime . runPromise (
58+ Effect . gen ( function * ( ) {
59+ return yield * File . Service . use ( ( svc ) => svc . status ( ) )
60+ } ) ,
61+ )
4862 process . stdout . write ( JSON . stringify ( status , null , 2 ) + EOL )
4963 } )
5064 } ,
@@ -61,7 +75,11 @@ const FileListCommand = cmd({
6175 } ) ,
6276 async handler ( args ) {
6377 await bootstrap ( process . cwd ( ) , async ( ) => {
64- const files = await File . list ( args . path )
78+ const files = await AppRuntime . runPromise (
79+ Effect . gen ( function * ( ) {
80+ return yield * File . Service . use ( ( svc ) => svc . list ( args . path ) )
81+ } ) ,
82+ )
6583 process . stdout . write ( JSON . stringify ( files , null , 2 ) + EOL )
6684 } )
6785 } ,
0 commit comments