#now we just need the PHP version doco'd

1 messages ยท Page 1 of 1 (latest)

ember kraken
#

@gritty mango can you get this to work?

#[DaggerFunction]
    #[Doc('Returns lines that match a pattern in the files of the provided Directory')]
    public function grepDir(
        #[DefaultPath('/')]
        Directory $source,
    ): string {
#

I get

! required flag(s) "source" not set
#

if I don't specify it

#

or #[DefaultPath('.')]

#

either one

#

Ah...guessing I need
use Dagger\Attribute\DefaultPath;

gritty mango
#

Add Intelephense extension on vscode, for full autocompletion and auto-adding 'use' things at the top

ember kraken
#

yep, was just freehanding a bit. A language server is a must

gritty mango
#

I found this

->withDirectory("/app", 
    $this->source-
>withoutDirectory(".dagger")
)

#

but this is on a withDirectory or withMountedDirectory call

#

I'm trying to exclude it when the module loads up .. since it's got #[DefaultPath(".")] right at the start of the module

#

4am - sleep time - but i've got a bunch of badass code here for the PHP Blog, and for my community call tomorrow.

Wanting to optimise things a bit .. and show excluding of ./vendor/ on module load .. coz that's how things are currently done in PHP, using .dockerignore

#

refresh gist - i added dagger.json

#

cya

ember kraken
#
<?php

declare(strict_types=1);

namespace DaggerModule;

use Dagger\Attribute\DaggerFunction;
use Dagger\Attribute\DaggerObject;
use Dagger\Attribute\DefaultPath;
use Dagger\Attribute\Ignore;
use Dagger\Attribute\Doc;
use Dagger\Directory;

use function Dagger\dag;

#[DaggerObject]
#[Doc('A generated module for ExIn functions')]
class ExIn
{
    #[DaggerFunction]
    #[Doc('Returns lines that match a pattern in the files of the provided Directory')]
    public function grepDir(
        #[Doc('Directory full of source code')]
        #[DefaultPath('/')]
        #[Ignore('vendor','one','two')]
        Directory $source,
    ): string {
        return dag()
            ->container()
            ->from('alpine:latest')
            ->withMountedDirectory('/mnt', $source)
            ->withWorkdir('/mnt')
            ->withExec(["grep", '-R', 'foo', '.'])
            ->stdout();
    }
}
#

that works ๐Ÿ™Œ have files with a bunch of "foo" in them in dirs one and two and also filter vendor

gritty mango
#

@ember kraken great job - thank you! I'll use Ignore annotation - nicely done.

#

sharing knowledge of this Annotation with you @hidden blaze @faint nacelle

faint nacelle
#

What Annotation sorry?
EDIT: Oh Ignore, yes, Chris asked me to add at the same time as DefaultPath since they were both to do with context directories

#

That gist looks good. Nice simple start with a popular framework ๐Ÿ‘