getGenerateCommandList method

Danger<List<Chain>, ChainException> getGenerateCommandList()

Implementation

Danger<List<Chain>, ChainException> getGenerateCommandList() {

    final log = Log(classLocation: runtimeType, functionLocation: 'getGenerateCommandList');

    final List<Body> bodyList = [];

    for (final i in globalArgumentList) {

        switch (i) {
        case FlagGlobalArgument():

            if (i.value) {

                final result = Flag.from(i.name);
                log.add(result);
                if (result is! Success<Flag, FlagException>) return Failure(result.asException, log);

                bodyList.add(result.wrapped);

            }

        case SingleGlobalArgument():

            final result = Variety.from(i.name, Some(i.value));
            log.add(result);
            if (result is! Success<Variety, VarietyException>) return Failure(result.asException, log);

            bodyList.add(result.wrapped);

        case MultipleGlobalArgument():

            final result = VarietyEnumeration.from(i.name, i.value);
            log.add(result);
            if (result is! Success<VarietyEnumeration, VarietyEnumerationException>) return Failure(result.asException, log);

            bodyList.add(result.wrapped);

        }

    }

    final globalChainResult = Chain.result(None(), bodyList);
    log.add(globalChainResult);
    if (globalChainResult is! Success<Chain, ChainException>) return Failure(globalChainResult.asException, log);
    final globalChain = globalChainResult.wrapped;

    final List<Chain> list = [];

    for (final i in generateList) {

        final chainResult = Chain.fromSource(i);
        log.add(chainResult);
        if (chainResult is! Success<Chain, ChainException>) return Failure(chainResult.asException, log);

        final result = globalChain.putAll(chainResult.wrapped.bodyList);
        log.add(result);
        if (result is! Success<Chain, ChainException>) return Failure(result.asException, log);

        list.add(result.wrapped);

    }

    return Success(list, log);

}